OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 private: | 51 private: |
52 ScopedTempDir temp_dir_; | 52 ScopedTempDir temp_dir_; |
53 base::FilePath path_; | 53 base::FilePath path_; |
54 }; | 54 }; |
55 | 55 |
56 const char kKey[] = "com.google.crashpad.test"; | 56 const char kKey[] = "com.google.crashpad.test"; |
57 | 57 |
58 TEST_F(Xattr, ReadNonExistentXattr) { | 58 TEST_F(Xattr, ReadNonExistentXattr) { |
59 std::string value; | 59 std::string value; |
60 EXPECT_FALSE(ReadXattr(path(), kKey, &value)); | 60 EXPECT_EQ(XattrStatus::kNoAttribute, ReadXattr(path(), kKey, &value)); |
61 } | 61 } |
62 | 62 |
63 TEST_F(Xattr, WriteAndReadString) { | 63 TEST_F(Xattr, WriteAndReadString) { |
64 std::string value = "hello world"; | 64 std::string value = "hello world"; |
65 EXPECT_TRUE(WriteXattr(path(), kKey, value)); | 65 EXPECT_TRUE(WriteXattr(path(), kKey, value)); |
66 | 66 |
67 std::string actual; | 67 std::string actual; |
68 EXPECT_TRUE(ReadXattr(path(), kKey, &actual)); | 68 EXPECT_EQ(XattrStatus::kOK, ReadXattr(path(), kKey, &actual)); |
69 EXPECT_EQ(value, actual); | 69 EXPECT_EQ(value, actual); |
70 } | 70 } |
71 | 71 |
72 TEST_F(Xattr, WriteAndReadVeryLongString) { | 72 TEST_F(Xattr, WriteAndReadVeryLongString) { |
73 std::string value(533, 'A'); | 73 std::string value(533, 'A'); |
74 EXPECT_TRUE(WriteXattr(path(), kKey, value)); | 74 EXPECT_TRUE(WriteXattr(path(), kKey, value)); |
75 | 75 |
76 std::string actual; | 76 std::string actual; |
77 EXPECT_TRUE(ReadXattr(path(), kKey, &actual)); | 77 EXPECT_EQ(XattrStatus::kOK, ReadXattr(path(), kKey, &actual)); |
78 EXPECT_EQ(value, actual); | 78 EXPECT_EQ(value, actual); |
79 } | 79 } |
80 | 80 |
81 TEST_F(Xattr, WriteAndReadBool) { | 81 TEST_F(Xattr, WriteAndReadBool) { |
82 EXPECT_TRUE(WriteXattrBool(path(), kKey, true)); | 82 EXPECT_TRUE(WriteXattrBool(path(), kKey, true)); |
83 bool actual = false; | 83 bool actual = false; |
84 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual)); | 84 EXPECT_EQ(XattrStatus::kOK, ReadXattrBool(path(), kKey, &actual)); |
85 EXPECT_TRUE(actual); | 85 EXPECT_TRUE(actual); |
86 | 86 |
87 EXPECT_TRUE(WriteXattrBool(path(), kKey, false)); | 87 EXPECT_TRUE(WriteXattrBool(path(), kKey, false)); |
88 EXPECT_TRUE(ReadXattrBool(path(), kKey, &actual)); | 88 EXPECT_EQ(XattrStatus::kOK, ReadXattrBool(path(), kKey, &actual)); |
89 EXPECT_FALSE(actual); | 89 EXPECT_FALSE(actual); |
90 } | 90 } |
91 | 91 |
92 TEST_F(Xattr, WriteAndReadInt) { | 92 TEST_F(Xattr, WriteAndReadInt) { |
93 int expected = 42; | 93 int expected = 42; |
94 int actual; | 94 int actual; |
95 | 95 |
96 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected)); | 96 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected)); |
97 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual)); | 97 EXPECT_EQ(XattrStatus::kOK, ReadXattrInt(path(), kKey, &actual)); |
98 EXPECT_EQ(expected, actual); | 98 EXPECT_EQ(expected, actual); |
99 | 99 |
100 expected = std::numeric_limits<int>::max(); | 100 expected = std::numeric_limits<int>::max(); |
101 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected)); | 101 EXPECT_TRUE(WriteXattrInt(path(), kKey, expected)); |
102 EXPECT_TRUE(ReadXattrInt(path(), kKey, &actual)); | 102 EXPECT_EQ(XattrStatus::kOK, ReadXattrInt(path(), kKey, &actual)); |
103 EXPECT_EQ(expected, actual); | 103 EXPECT_EQ(expected, actual); |
104 } | 104 } |
105 | 105 |
106 TEST_F(Xattr, WriteAndReadTimeT) { | 106 TEST_F(Xattr, WriteAndReadTimeT) { |
107 time_t expected = time(nullptr); | 107 time_t expected = time(nullptr); |
108 time_t actual; | 108 time_t actual; |
109 | 109 |
110 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected)); | 110 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected)); |
111 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual)); | 111 EXPECT_EQ(XattrStatus::kOK, ReadXattrTimeT(path(), kKey, &actual)); |
112 EXPECT_EQ(expected, actual); | 112 EXPECT_EQ(expected, actual); |
113 | 113 |
114 expected = std::numeric_limits<time_t>::max(); | 114 expected = std::numeric_limits<time_t>::max(); |
115 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected)); | 115 EXPECT_TRUE(WriteXattrTimeT(path(), kKey, expected)); |
116 EXPECT_TRUE(ReadXattrTimeT(path(), kKey, &actual)); | 116 EXPECT_EQ(XattrStatus::kOK, ReadXattrTimeT(path(), kKey, &actual)); |
117 EXPECT_EQ(expected, actual); | 117 EXPECT_EQ(expected, actual); |
118 } | 118 } |
119 | 119 |
120 } // namespace | 120 } // namespace |
121 } // namespace test | 121 } // namespace test |
122 } // namespace crashpad | 122 } // namespace crashpad |
OLD | NEW |