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

Side by Side Diff: native_client_sdk/src/tests/nacl_io_test/fuse_fs_test.cc

Issue 549353003: [NaCl SDK] nacl_io: Fix FuseFs.{read,write} (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <fcntl.h> 5 #include <fcntl.h>
6 6
7 #include <gtest/gtest.h> 7 #include <gtest/gtest.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 } // namespace 215 } // namespace
216 216
217 TEST_F(FuseFsTest, OpenAndRead) { 217 TEST_F(FuseFsTest, OpenAndRead) {
218 ScopedNode node; 218 ScopedNode node;
219 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node)); 219 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node));
220 220
221 char buffer[15] = {0}; 221 char buffer[15] = {0};
222 int bytes_read = 0; 222 int bytes_read = 0;
223 HandleAttr attr; 223 HandleAttr attr;
224 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read)); 224 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
225 // FUSE always fills the buffer (padding with \0) unless in direct_io mode. 225 ASSERT_EQ(strlen(hello_world), bytes_read);
226 ASSERT_EQ(sizeof(buffer), bytes_read);
227 ASSERT_STREQ(hello_world, buffer); 226 ASSERT_STREQ(hello_world, buffer);
227
228 // Try to read past the end of the file.
229 attr.offs = strlen(hello_world) - 7;
230 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
231 ASSERT_EQ(7, bytes_read);
232 ASSERT_STREQ("World!\n", buffer);
228 } 233 }
229 234
230 TEST_F(FuseFsTest, CreateAndWrite) { 235 TEST_F(FuseFsTest, CreateAndWrite) {
231 ScopedNode node; 236 ScopedNode node;
232 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node)); 237 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node));
233 238
234 HandleAttr attr; 239 HandleAttr attr;
235 const char message[] = "Something interesting"; 240 const char message[] = "Something interesting";
236 int bytes_written; 241 int bytes_written;
237 ASSERT_EQ(0, node->Write(attr, &message[0], strlen(message), &bytes_written)); 242 ASSERT_EQ(0, node->Write(attr, &message[0], strlen(message), &bytes_written));
238 ASSERT_EQ(bytes_written, strlen(message)); 243 ASSERT_EQ(bytes_written, strlen(message));
239 244
240 // Now try to read the data back. 245 // Now try to read the data back.
241 char buffer[40] = {0}; 246 char buffer[40] = {0};
242 int bytes_read = 0; 247 int bytes_read = 0;
243 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read)); 248 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
244 // FUSE always fills the buffer (padding with \0) unless in direct_io mode. 249 ASSERT_EQ(strlen(message), bytes_read);
245 ASSERT_EQ(sizeof(buffer), bytes_read);
246 ASSERT_STREQ(message, buffer); 250 ASSERT_STREQ(message, buffer);
247 } 251 }
248 252
249 TEST_F(FuseFsTest, GetStat) { 253 TEST_F(FuseFsTest, GetStat) {
250 struct stat statbuf; 254 struct stat statbuf;
251 ScopedNode node; 255 ScopedNode node;
252 256
253 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node)); 257 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node));
254 EXPECT_EQ(0, node->GetStat(&statbuf)); 258 EXPECT_EQ(0, node->GetStat(&statbuf));
255 EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT); 259 EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT);
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 ASSERT_EQ(sizeof(hello_world), 346 ASSERT_EQ(sizeof(hello_world),
343 ki_write(fd, hello_world, sizeof(hello_world))); 347 ki_write(fd, hello_world, sizeof(hello_world)));
344 EXPECT_EQ(0, ki_close(fd)); 348 EXPECT_EQ(0, ki_close(fd));
345 349
346 // Then read it back in. 350 // Then read it back in.
347 fd = ki_open("/hello", O_RDONLY); 351 fd = ki_open("/hello", O_RDONLY);
348 ASSERT_GT(fd, -1); 352 ASSERT_GT(fd, -1);
349 353
350 char buffer[30]; 354 char buffer[30];
351 memset(buffer, 0, sizeof(buffer)); 355 memset(buffer, 0, sizeof(buffer));
352 ASSERT_EQ(sizeof(buffer), ki_read(fd, buffer, sizeof(buffer))); 356 ASSERT_EQ(sizeof(hello_world), ki_read(fd, buffer, sizeof(buffer)));
353 EXPECT_STREQ(hello_world, buffer); 357 EXPECT_STREQ(hello_world, buffer);
354 EXPECT_EQ(0, ki_close(fd)); 358 EXPECT_EQ(0, ki_close(fd));
355 } 359 }
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/fusefs/fuse_fs.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698