Chromium Code Reviews

Side by Side Diff: mojo/services/files/public/c/tests/mojio_sys_stat_unittest.cc

Issue 1388413005: Move //mojo/services/X/public/... to //mojo/services/X/... (part 1). (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
(Empty)
1 // Copyright 2015 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 // Basic tests of things declared in mojio_sys_stat.h. Note that more thorough
6 // tests are done more directly at a different level.
7
8 #include <errno.h>
9 #include <string.h>
10
11 #include "files/public/c/mojio_fcntl.h"
12 #include "files/public/c/mojio_sys_stat.h"
13 #include "files/public/c/mojio_unistd.h"
14 #include "files/public/c/tests/mojio_test_base.h"
15
16 namespace {
17
18 using MojioSysStatTest = mojio::test::MojioTestBase;
19
20 TEST_F(MojioSysStatTest, Fstat) {
21 const char kTestData[511] = {};
22
23 int fd = mojio_creat("my_file", MOJIO_S_IRWXU);
24 EXPECT_GE(fd, 0);
25
26 errno = 12345;
27 struct mojio_stat buf = {};
28 int result = mojio_fstat(fd, &buf);
29 int errno_value = errno;
30 EXPECT_EQ(0, result);
31 EXPECT_EQ(12345, errno_value);
32 // Note: Don't check the unfilled values. (Some of the checks may also be
33 // fragile, depending on our level of support.)
34 EXPECT_EQ(static_cast<mojio_mode_t>(MOJIO_S_IRWXU | MOJIO_S_IFREG),
35 buf.st_mode); // Fragile.
36 EXPECT_EQ(1u, buf.st_nlink); // Fragile.
37 EXPECT_EQ(0, buf.st_size);
38 // Just check that |st_atim.tv_sec|, etc. are positive (a bit fragile).
39 EXPECT_GT(buf.st_atim.tv_sec, 0);
40 EXPECT_GT(buf.st_mtim.tv_sec, 0);
41 EXPECT_GT(buf.st_ctim.tv_sec, 0);
42 EXPECT_EQ(1024, buf.st_blksize); // Fragile.
43 EXPECT_EQ(0u, buf.st_blocks);
44
45 // We use various assumptions below about the amount that we write, so we may
46 // as well assert this here.
47 static_assert(sizeof(kTestData) == 511, "oops");
48 EXPECT_EQ(511, mojio_write(fd, kTestData, 511));
49
50 memset(&buf, 0, sizeof(buf));
51 EXPECT_EQ(0, mojio_fstat(fd, &buf));
52 EXPECT_EQ(511, buf.st_size);
53 EXPECT_EQ(1u, buf.st_blocks);
54
55 EXPECT_EQ(511, mojio_write(fd, kTestData, 511));
56
57 memset(&buf, 0, sizeof(buf));
58 EXPECT_EQ(0, mojio_fstat(fd, &buf));
59 EXPECT_EQ(1022, buf.st_size);
60 EXPECT_EQ(2u, buf.st_blocks);
61
62 EXPECT_EQ(0, mojio_close(fd));
63 }
64
65 TEST_F(MojioSysStatTest, Ebadf) {
66 struct mojio_stat buf = {};
67 errno = 12345;
68 int result = mojio_fstat(-1, &buf);
69 int errno_value = errno;
70 EXPECT_EQ(-1, result);
71 EXPECT_EQ(EBADF, errno_value);
72 }
73
74 } // namespace
OLDNEW
« no previous file with comments | « mojo/services/files/public/c/tests/mojio_impl_test_base.cc ('k') | mojo/services/files/public/c/tests/mojio_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine