Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: native_client_sdk/src/libraries/nacl_mounts_test/kernel_wrap_test.cc

Issue 11066105: [NaCl SDK] nacl_mounts: wrap functions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
4 */
5
6 #include <string>
7 #include <vector>
8 #include "gtest/gtest.h"
9 #include "nacl_mounts/kernel_proxy.h"
10 #include "nacl_mounts/kernel_intercept.h"
11 #include "nacl_mounts/kernel_wrap.h"
12 #include "kernel_proxy_mock.h"
13
14 using ::testing::StrEq;
15 using ::testing::_;
16
17 namespace {
18
19 #define COMPARE_FIELD(f) \
20 if (arg->f != statbuf->f) { \
21 *result_listener << "mismatch of field \""#f"\". " \
22 "expected: " << statbuf->f << \
23 " actual: " << arg->f; \
24 return false; \
25 }
26
27 MATCHER_P(IsEqualToStatbuf, statbuf, "") {
28 COMPARE_FIELD(st_dev);
29 COMPARE_FIELD(st_ino);
30 COMPARE_FIELD(st_mode);
31 COMPARE_FIELD(st_nlink);
32 COMPARE_FIELD(st_uid);
33 COMPARE_FIELD(st_gid);
34 COMPARE_FIELD(st_rdev);
35 COMPARE_FIELD(st_size);
36 COMPARE_FIELD(st_atime);
37 COMPARE_FIELD(st_mtime);
38 COMPARE_FIELD(st_ctime);
39 return true;
40 }
41
42 #undef COMPARE_FIELD
43
44 ACTION_P(SetStat, statbuf) {
45 memset(arg1, 0, sizeof(struct stat));
46 arg1->st_dev = statbuf->st_dev;
47 arg1->st_ino = statbuf->st_ino;
48 arg1->st_mode = statbuf->st_mode;
49 arg1->st_nlink = statbuf->st_nlink;
50 arg1->st_uid = statbuf->st_uid;
51 arg1->st_gid = statbuf->st_gid;
52 arg1->st_rdev = statbuf->st_rdev;
53 arg1->st_size = statbuf->st_size;
54 arg1->st_atime = statbuf->st_atime;
55 arg1->st_mtime = statbuf->st_mtime;
56 arg1->st_ctime = statbuf->st_ctime;
57 return 0;
58 }
59
60 void MakeDummyStatbuf(struct stat* statbuf) {
61 memset(&statbuf[0], 0, sizeof(struct stat));
62 statbuf->st_dev = 1;
63 statbuf->st_ino = 2;
64 statbuf->st_mode = 3;
65 statbuf->st_nlink = 4;
66 statbuf->st_uid = 5;
67 statbuf->st_gid = 6;
68 statbuf->st_rdev = 7;
69 statbuf->st_size = 8;
70 statbuf->st_atime = 9;
71 statbuf->st_mtime = 10;
72 statbuf->st_ctime = 11;
73 }
74
75 } // namespace
76
77 TEST(KernelWrap, access) {
78 KernelProxyMock mock;
79 ki_init(&mock);
80 EXPECT_CALL(mock, access(StrEq("access"), 12)).Times(1);
81 access("access", 12);
82 }
83
84 TEST(KernelWrap, chdir) {
85 KernelProxyMock mock;
86 ki_init(&mock);
87 EXPECT_CALL(mock, chdir(StrEq("chdir"))).Times(1);
88 chdir("chdir");
89 }
90
91 TEST(KernelWrap, chmod) {
92 KernelProxyMock mock;
93 ki_init(&mock);
94 EXPECT_CALL(mock, chmod(StrEq("chmod"), 23)).Times(1);
95 chmod("chmod", 23);
96 }
97
98 TEST(KernelWrap, close) {
99 KernelProxyMock mock;
100 ki_init(&mock);
101 EXPECT_CALL(mock, close(34)).Times(1);
102 close(34);
103 }
104
105 TEST(KernelWrap, dup) {
106 KernelProxyMock mock;
107 ki_init(&mock);
108 EXPECT_CALL(mock, dup(123)).Times(1);
109 dup(123);
110 }
111
112 TEST(KernelWrap, fstat) {
113 KernelProxyMock mock;
114 ki_init(&mock);
115 struct stat in_statbuf;
116 MakeDummyStatbuf(&in_statbuf);
117 EXPECT_CALL(mock, fstat(234, _))
118 .Times(1)
119 .WillOnce(SetStat(&in_statbuf));
120 struct stat out_statbuf;
121 fstat(234, &out_statbuf);
122 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
123 }
124
125 TEST(KernelWrap, fsync) {
126 KernelProxyMock mock;
127 ki_init(&mock);
128 EXPECT_CALL(mock, fsync(345)).Times(1);
129 fsync(345);
130 }
131
132 TEST(KernelWrap, getcwd) {
133 KernelProxyMock mock;
134 ki_init(&mock);
135 EXPECT_CALL(mock, getcwd(StrEq("getcwd"), 1)).Times(1);
136 char buffer[] = "getcwd";
137 getcwd(buffer, 1);
138 }
139
140 TEST(KernelWrap, getdents) {
141 KernelProxyMock mock;
142 ki_init(&mock);
143 EXPECT_CALL(mock, getdents(456, NULL, 567)).Times(1);
144 getdents(456, NULL, 567);
145 }
146
147 #if 0
noelallen1 2012/10/16 20:22:57 Did you mean to leave this here?
148 // gcc gives error: getwd is deprecated.
149 TEST(KernelWrap, getwd) {
150 KernelProxyMock mock;
151 ki_init(&mock);
152 EXPECT_CALL(mock, getwd(StrEq("getwd"))).Times(1);
153 char buffer[] = "getwd";
154 getwd(buffer);
155 }
156 #endif
157
158 TEST(KernelWrap, isatty) {
159 KernelProxyMock mock;
160 ki_init(&mock);
161 EXPECT_CALL(mock, isatty(678)).Times(1);
162 isatty(678);
163 }
164
165 TEST(KernelWrap, lseek) {
166 KernelProxyMock mock;
167 ki_init(&mock);
168 EXPECT_CALL(mock, lseek(789, 891, 912)).Times(1);
169 lseek(789, 891, 912);
170 }
171
172 TEST(KernelWrap, mkdir) {
173 KernelProxyMock mock;
174 ki_init(&mock);
175 #if defined(WIN32)
176 EXPECT_CALL(mock, mkdir(StrEq("mkdir"), 0777)).Times(1);
177 mkdir("mkdir");
178 #else
179 EXPECT_CALL(mock, mkdir(StrEq("mkdir"), 1234)).Times(1);
180 mkdir("mkdir", 1234);
181 #endif
182 }
183
184 TEST(KernelWrap, mount) {
185 KernelProxyMock mock;
186 ki_init(&mock);
187 EXPECT_CALL(mock,
188 mount(StrEq("mount1"), StrEq("mount2"), StrEq("mount3"), 2345, NULL))
189 .Times(1);
190 mount("mount1", "mount2", "mount3", 2345, NULL);
191 }
192
193 TEST(KernelWrap, open) {
194 KernelProxyMock mock;
195 ki_init(&mock);
196 EXPECT_CALL(mock, open(StrEq("open"), 3456)).Times(1);
197 open("open", 3456);
198 }
199
200 TEST(KernelWrap, read) {
201 KernelProxyMock mock;
202 ki_init(&mock);
203 EXPECT_CALL(mock, read(4567, NULL, 5678)).Times(1);
204 read(4567, NULL, 5678);
205 }
206
207 TEST(KernelWrap, remove) {
208 KernelProxyMock mock;
209 ki_init(&mock);
210 EXPECT_CALL(mock, remove(StrEq("remove"))).Times(1);
211 remove("remove");
212 }
213
214 TEST(KernelWrap, rmdir) {
215 KernelProxyMock mock;
216 ki_init(&mock);
217 EXPECT_CALL(mock, rmdir(StrEq("rmdir"))).Times(1);
218 rmdir("rmdir");
219 }
220
221 TEST(KernelWrap, stat) {
222 KernelProxyMock mock;
223 ki_init(&mock);
224 struct stat in_statbuf;
225 MakeDummyStatbuf(&in_statbuf);
226 EXPECT_CALL(mock, stat(StrEq("stat"), _))
227 .Times(1)
228 .WillOnce(SetStat(&in_statbuf));
229 struct stat out_statbuf;
230 stat("stat", &out_statbuf);
231 EXPECT_THAT(&in_statbuf, IsEqualToStatbuf(&out_statbuf));
232 }
233
234 TEST(KernelWrap, umount) {
235 KernelProxyMock mock;
236 ki_init(&mock);
237 EXPECT_CALL(mock, umount(StrEq("umount"))).Times(1);
238 umount("umount");
239 }
240
241 TEST(KernelWrap, unlink) {
242 KernelProxyMock mock;
243 ki_init(&mock);
244 EXPECT_CALL(mock, unlink(StrEq("unlink"))).Times(1);
245 unlink("unlink");
246 }
247
248 TEST(KernelWrap, write) {
249 KernelProxyMock mock;
250 ki_init(&mock);
251 EXPECT_CALL(mock, write(6789, NULL, 7891)).Times(1);
252 write(6789, NULL, 7891);
253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698