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

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: For landing Created 5 years, 11 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 | « util/mac/xattr.cc ('k') | util/util.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 The Crashpad Authors. All rights reserved.
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/posix/eintr_wrapper.h"
25 #include "base/strings/stringprintf.h"
26 #include "gtest/gtest.h"
27 #include "util/test/errors.h"
28
29 namespace crashpad {
30 namespace test {
31 namespace {
32
33 class Xattr : public testing::Test {
34 public:
35 // testing::Test:
36
37 void SetUp() override {
38 path_ = base::FilePath(
39 base::StringPrintf("/tmp/com.googlecode.crashpad.test.xattr.%d.%p",
40 getpid(), this));
41 // TODO(rsesek): This should use something like ScopedTempDir.
42 base::ScopedFD tmp(HANDLE_EINTR(
43 open(path_.value().c_str(), O_CREAT | O_TRUNC, 0644)));
44 EXPECT_GE(tmp.get(), 0) << ErrnoMessage("open");
45 }
46
47 void TearDown() override {
48 EXPECT_EQ(0, unlink(path_.value().c_str())) << ErrnoMessage("unlink");
49 }
50
51 base::FilePath path() { return path_; }
52
53 private:
54 base::FilePath path_;
55 };
56
57 const char kKey[] = "com.google.crashpad.test";
58
59 TEST_F(Xattr, ReadNonExistentXattr) {
60 std::string value;
61 EXPECT_FALSE(ReadXattr(path(), kKey, &value));
62 }
63
64 TEST_F(Xattr, WriteAndReadString) {
65 std::string value = "hello world";
66 EXPECT_TRUE(WriteXattr(path(), kKey, value));
67
68 std::string actual;
69 EXPECT_TRUE(ReadXattr(path(), kKey, &actual));
70 EXPECT_EQ(value, actual);
71 }
72
73 TEST_F(Xattr, WriteAndReadVeryLongString) {
74 std::string value(533, 'A');
75 EXPECT_TRUE(WriteXattr(path(), kKey, value));
76
77 std::string actual;
78 EXPECT_TRUE(ReadXattr(path(), kKey, &actual));
79 EXPECT_EQ(value, actual);
80 }
81
82 TEST_F(Xattr, WriteAndReadBool) {
83 EXPECT_TRUE(WriteXattrBool(path(), kKey, true));
84 bool actual = false;
85 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual));
86 EXPECT_TRUE(actual);
87
88 EXPECT_TRUE(WriteXattrBool(path(), kKey, false));
89 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual));
90 EXPECT_FALSE(actual);
91 }
92
93 TEST_F(Xattr, WriteAndReadInt) {
94 int expected = 42;
95 int actual;
96
97 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected));
98 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual));
99 EXPECT_EQ(expected, actual);
100
101 expected = std::numeric_limits<int>::max();
102 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected));
103 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual));
104 EXPECT_EQ(expected, actual);
105 }
106
107 TEST_F(Xattr, WriteAndReadTimeT) {
108 time_t expected = time(nullptr);
109 time_t actual;
110
111 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected));
112 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual));
113 EXPECT_EQ(expected, actual);
114
115 expected = std::numeric_limits<time_t>::max();
116 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected));
117 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual));
118 EXPECT_EQ(expected, actual);
119 }
120
121 } // namespace
122 } // namespace test
123 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/mac/xattr.cc ('k') | util/util.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698