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

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

Issue 660353003: [NaCl SDK] nacl_io: Fix utime() on directories. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 ASSERT_STREQ("World!\n", buffer); 282 ASSERT_STREQ("World!\n", buffer);
283 } 283 }
284 284
285 TEST_F(FuseFsTest, CreateWithMode) { 285 TEST_F(FuseFsTest, CreateWithMode) {
286 ScopedNode node; 286 ScopedNode node;
287 struct stat statbuf; 287 struct stat statbuf;
288 288
289 ASSERT_EQ(0, fs_.OpenWithMode(Path("/hello"), 289 ASSERT_EQ(0, fs_.OpenWithMode(Path("/hello"),
290 O_RDWR | O_CREAT, 0723, &node)); 290 O_RDWR | O_CREAT, 0723, &node));
291 EXPECT_EQ(0, node->GetStat(&statbuf)); 291 EXPECT_EQ(0, node->GetStat(&statbuf));
292 EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT); 292 EXPECT_TRUE(S_ISREG(statbuf.st_mode));
293 EXPECT_EQ(0723, statbuf.st_mode & ~S_IFMT); 293 EXPECT_EQ(0723, statbuf.st_mode & 0777);
294 } 294 }
295 295
296 TEST_F(FuseFsTest, CreateAndWrite) { 296 TEST_F(FuseFsTest, CreateAndWrite) {
297 ScopedNode node; 297 ScopedNode node;
298 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node)); 298 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node));
299 299
300 HandleAttr attr; 300 HandleAttr attr;
301 const char message[] = "Something interesting"; 301 const char message[] = "Something interesting";
302 int bytes_written; 302 int bytes_written;
303 ASSERT_EQ(0, node->Write(attr, &message[0], strlen(message), &bytes_written)); 303 ASSERT_EQ(0, node->Write(attr, &message[0], strlen(message), &bytes_written));
304 ASSERT_EQ(bytes_written, strlen(message)); 304 ASSERT_EQ(bytes_written, strlen(message));
305 305
306 // Now try to read the data back. 306 // Now try to read the data back.
307 char buffer[40] = {0}; 307 char buffer[40] = {0};
308 int bytes_read = 0; 308 int bytes_read = 0;
309 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read)); 309 ASSERT_EQ(0, node->Read(attr, &buffer[0], sizeof(buffer), &bytes_read));
310 ASSERT_EQ(strlen(message), bytes_read); 310 ASSERT_EQ(strlen(message), bytes_read);
311 ASSERT_STREQ(message, buffer); 311 ASSERT_STREQ(message, buffer);
312 } 312 }
313 313
314 TEST_F(FuseFsTest, GetStat) { 314 TEST_F(FuseFsTest, GetStat) {
315 struct stat statbuf; 315 struct stat statbuf;
316 ScopedNode node; 316 ScopedNode node;
317 317
318 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node)); 318 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node));
319 EXPECT_EQ(0, node->GetStat(&statbuf)); 319 EXPECT_EQ(0, node->GetStat(&statbuf));
320 EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT); 320 EXPECT_TRUE(S_ISREG(statbuf.st_mode));
321 EXPECT_EQ(0666, statbuf.st_mode & ~S_IFMT); 321 EXPECT_EQ(0666, statbuf.st_mode & 0777);
322 EXPECT_EQ(strlen(hello_world), statbuf.st_size); 322 EXPECT_EQ(strlen(hello_world), statbuf.st_size);
323 323
324 ASSERT_EQ(0, fs_.Open(Path("/"), O_RDONLY, &node)); 324 ASSERT_EQ(0, fs_.Open(Path("/"), O_RDONLY, &node));
325 EXPECT_EQ(0, node->GetStat(&statbuf)); 325 EXPECT_EQ(0, node->GetStat(&statbuf));
326 EXPECT_EQ(S_IFDIR, statbuf.st_mode & S_IFMT); 326 EXPECT_TRUE(S_ISDIR(statbuf.st_mode));
327 EXPECT_EQ(0755, statbuf.st_mode & ~S_IFMT); 327 EXPECT_EQ(0755, statbuf.st_mode & 0777);
328 328
329 // Create a file and stat. 329 // Create a file and stat.
330 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node)); 330 ASSERT_EQ(0, fs_.Open(Path("/foobar"), O_RDWR | O_CREAT, &node));
331 EXPECT_EQ(0, node->GetStat(&statbuf)); 331 EXPECT_EQ(0, node->GetStat(&statbuf));
332 EXPECT_EQ(S_IFREG, statbuf.st_mode & S_IFMT); 332 EXPECT_TRUE(S_ISREG(statbuf.st_mode));
333 EXPECT_EQ(0666, statbuf.st_mode & ~S_IFMT); 333 EXPECT_EQ(0666, statbuf.st_mode & 0777);
334 EXPECT_EQ(0, statbuf.st_size); 334 EXPECT_EQ(0, statbuf.st_size);
335 } 335 }
336 336
337 TEST_F(FuseFsTest, GetDents) { 337 TEST_F(FuseFsTest, GetDents) {
338 ScopedNode root; 338 ScopedNode root;
339 339
340 ASSERT_EQ(0, fs_.Open(Path("/"), O_RDONLY, &root)); 340 ASSERT_EQ(0, fs_.Open(Path("/"), O_RDONLY, &root));
341 341
342 struct dirent entries[4]; 342 struct dirent entries[4];
343 int bytes_read; 343 int bytes_read;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 EXPECT_EQ(times[1].tv_sec, statbuf.st_mtime); 387 EXPECT_EQ(times[1].tv_sec, statbuf.st_mtime);
388 EXPECT_EQ(times[1].tv_nsec, statbuf.st_mtimensec); 388 EXPECT_EQ(times[1].tv_nsec, statbuf.st_mtimensec);
389 } 389 }
390 390
391 TEST_F(FuseFsTest, Fchmod) { 391 TEST_F(FuseFsTest, Fchmod) {
392 struct stat statbuf; 392 struct stat statbuf;
393 ScopedNode node; 393 ScopedNode node;
394 394
395 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node)); 395 ASSERT_EQ(0, fs_.Open(Path("/hello"), O_RDONLY, &node));
396 ASSERT_EQ(0, node->GetStat(&statbuf)); 396 ASSERT_EQ(0, node->GetStat(&statbuf));
397 EXPECT_EQ(0666, statbuf.st_mode & ~S_IFMT); 397 EXPECT_EQ(0666, statbuf.st_mode & 0777);
398 398
399 ASSERT_EQ(0, node->Fchmod(0777)); 399 ASSERT_EQ(0, node->Fchmod(0777));
400 400
401 ASSERT_EQ(0, node->GetStat(&statbuf)); 401 ASSERT_EQ(0, node->GetStat(&statbuf));
402 EXPECT_EQ(0777, statbuf.st_mode & ~S_IFMT); 402 EXPECT_EQ(0777, statbuf.st_mode & 0777);
403 } 403 }
404 404
405 namespace { 405 namespace {
406 406
407 class KernelProxyFuseTest : public ::testing::Test { 407 class KernelProxyFuseTest : public ::testing::Test {
408 public: 408 public:
409 KernelProxyFuseTest() {} 409 KernelProxyFuseTest() {}
410 410
411 void SetUp(); 411 void SetUp();
412 void TearDown(); 412 void TearDown();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 // Then read it back in. 445 // Then read it back in.
446 fd = ki_open("/hello", O_RDONLY, 0); 446 fd = ki_open("/hello", O_RDONLY, 0);
447 ASSERT_GT(fd, -1); 447 ASSERT_GT(fd, -1);
448 448
449 char buffer[30]; 449 char buffer[30];
450 memset(buffer, 0, sizeof(buffer)); 450 memset(buffer, 0, sizeof(buffer));
451 ASSERT_EQ(sizeof(hello_world), ki_read(fd, buffer, sizeof(buffer))); 451 ASSERT_EQ(sizeof(hello_world), ki_read(fd, buffer, sizeof(buffer)));
452 EXPECT_STREQ(hello_world, buffer); 452 EXPECT_STREQ(hello_world, buffer);
453 EXPECT_EQ(0, ki_close(fd)); 453 EXPECT_EQ(0, ki_close(fd));
454 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698