OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "client/settings.h" |
| 16 |
| 17 #include "client/crash_report_database.h" |
| 18 #include "gtest/gtest.h" |
| 19 #include "util/test/scoped_temp_dir.h" |
| 20 |
| 21 namespace crashpad { |
| 22 namespace test { |
| 23 namespace { |
| 24 |
| 25 class SettingsTest : public testing::Test { |
| 26 public: |
| 27 SettingsTest() {} |
| 28 |
| 29 Settings* settings() { return db_->GetSettings(); } |
| 30 |
| 31 protected: |
| 32 // testing::Test: |
| 33 void SetUp() override { |
| 34 ReopenDatabase(); |
| 35 } |
| 36 |
| 37 void ReopenDatabase() { |
| 38 db_.reset(); |
| 39 db_ = CrashReportDatabase::Initialize(temp_dir_.path()); |
| 40 ASSERT_TRUE(db_); |
| 41 } |
| 42 |
| 43 private: |
| 44 ScopedTempDir temp_dir_; |
| 45 scoped_ptr<CrashReportDatabase> db_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(SettingsTest); |
| 48 }; |
| 49 |
| 50 TEST_F(SettingsTest, ClientID) { |
| 51 std::string client_id; |
| 52 EXPECT_TRUE(settings()->GetClientID(&client_id)); |
| 53 EXPECT_FALSE(client_id.empty()); |
| 54 |
| 55 ReopenDatabase(); |
| 56 |
| 57 std::string actual; |
| 58 EXPECT_TRUE(settings()->GetClientID(&actual)); |
| 59 EXPECT_EQ(client_id, actual); |
| 60 } |
| 61 |
| 62 TEST_F(SettingsTest, UploadsEnabled) { |
| 63 bool enabled = true; |
| 64 // Default value is false. |
| 65 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled)); |
| 66 EXPECT_FALSE(enabled); |
| 67 |
| 68 EXPECT_TRUE(settings()->SetUploadsEnabled(true)); |
| 69 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled)); |
| 70 EXPECT_TRUE(enabled); |
| 71 |
| 72 EXPECT_TRUE(settings()->SetUploadsEnabled(false)); |
| 73 EXPECT_TRUE(settings()->GetUploadsEnabled(&enabled)); |
| 74 EXPECT_FALSE(enabled); |
| 75 } |
| 76 |
| 77 TEST_F(SettingsTest, LastUploadAttemptTime) { |
| 78 time_t actual = -1; |
| 79 EXPECT_TRUE(settings()->GetLastUploadAttemptTime(&actual)); |
| 80 // Default value is 0. |
| 81 EXPECT_EQ(0, actual); |
| 82 |
| 83 time_t expected = time(nullptr); |
| 84 EXPECT_TRUE(settings()->SetLastUploadAttemptTime(expected)); |
| 85 EXPECT_TRUE(settings()->GetLastUploadAttemptTime(&actual)); |
| 86 EXPECT_EQ(expected, actual); |
| 87 } |
| 88 |
| 89 } // namespace |
| 90 } // namespace test |
| 91 } // namespace crashpad |
OLD | NEW |