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

Side by Side Diff: util/mac/xattr_test.cc

Issue 791493009: Add wrappers around getxattr() and setxattr(). (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
Mark Mentovai 2014/12/19 23:16:32 CL description: TEST=
Robert Sesek 2014/12/30 17:02:21 Done.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "util/mac/xattr.h"
16
17 #include <fcntl.h>
18 #include <sys/stat.h>
19 #include <unistd.h>
20
21 #include <limits>
22
23 #include "base/files/scoped_file.h"
24 #include "base/strings/stringprintf.h"
25 #include "gtest/gtest.h"
26
27 namespace crashpad {
28 namespace test {
29 namespace {
30
31 class Xattr : public testing::Test {
32 public:
33 void SetUp() override {
Mark Mentovai 2014/12/19 23:16:32 // testing::Test: to tell what it’s overriding (al
Robert Sesek 2014/12/30 17:02:21 Done.
34 path_ = base::FilePath(
35 base::StringPrintf("/tmp/com.google.crashpad.test.xattr.%p", this));
Mark Mentovai 2014/12/19 23:16:32 org.googlecode.crashpad
Robert Sesek 2014/12/30 17:02:21 Done.
36 base::ScopedFD tmp(open(path_.value().c_str(), O_CREAT | O_TRUNC, S_IRWXU));
Mark Mentovai 2014/12/19 23:16:32 You don’t want the x-bit. S_IRUSR | S_IWUSR. I’d p
Robert Sesek 2014/12/30 17:02:21 Done.
37 EXPECT_GE(tmp.get(), 0) << errno;
Mark Mentovai 2014/12/19 23:16:32 #include "util/test/errros.h" and use << ErrnoMess
Robert Sesek 2014/12/30 17:02:21 Done.
38 }
39
40 void TearDown() override {
41 EXPECT_EQ(0, unlink(path_.value().c_str())) << errno;
42 }
43
44 base::FilePath path() { return path_; }
45
46 private:
47 base::FilePath path_;
48 };
49
50 const char kKey[] = "com.google.crashpad.test";
51
52 TEST_F(Xattr, ReadNonExistentXattr) {
53 std::string value;
54 EXPECT_FALSE(ReadXattr(path(), kKey, &value));
55 }
56
57 TEST_F(Xattr, WriteAndReadString) {
58 std::string value = "hello world";
59 EXPECT_TRUE(WriteXattr(path(), kKey, value));
60
61 std::string actual;
62 EXPECT_TRUE(ReadXattr(path(), kKey, &actual));
63 EXPECT_EQ(value, actual);
64 }
65
66 TEST_F(Xattr, WriteAndReadVeryLongString) {
67 std::string value(512, 'A');
Mark Mentovai 2014/12/19 23:16:32 Maybe a not-power-of-2-aligned-length string?
Robert Sesek 2014/12/30 17:02:21 Done.
68 EXPECT_TRUE(WriteXattr(path(), kKey, value));
69
70 std::string actual;
71 EXPECT_TRUE(ReadXattr(path(), kKey, &actual));
72 EXPECT_EQ(value, actual);
73 }
74
75 TEST_F(Xattr, WriteAndReadBool) {
76 EXPECT_TRUE(WriteXattrBool(path(), kKey, true));
77 bool actual = false;
78 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual));
79 EXPECT_TRUE(actual);
80
81 EXPECT_TRUE(WriteXattrBool(path(), kKey, false));
82 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual));
83 EXPECT_FALSE(actual);
84 }
85
86 TEST_F(Xattr, WriteAndReadInt) {
87 int expected = 42;
88 int actual;
89
90 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected));
91 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual));
92 EXPECT_EQ(expected, actual);
93
94 expected = std::numeric_limits<int>::max();
95 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected));
96 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual));
97 EXPECT_EQ(expected, actual);
98 }
99
100 TEST_F(Xattr, WriteAndReadTimeT) {
101 time_t expected = time(nullptr);
102 time_t actual;
103
104 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected));
105 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual));
106 EXPECT_EQ(expected, actual);
107
108 expected = std::numeric_limits<time_t>::max();
109 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected));
110 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual));
111 EXPECT_EQ(expected, actual);
112 }
113
114 } // namespace
115 } // namespace test
116 } // namespace crashpad
OLDNEW
« util/mac/xattr.cc ('K') | « util/mac/xattr.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698