Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS 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 | #include <gtest/gtest.h> |
| 6 | |
| 7 | #include "shill/dbus_properties.h" |
| 8 | |
| 9 | using std::string; |
| 10 | using testing::Test; |
| 11 | |
| 12 | namespace shill { |
| 13 | |
| 14 | class DBusPropertiesTest : public Test { |
| 15 | }; |
| 16 | |
| 17 | TEST_F(DBusPropertiesTest, GetString) { |
| 18 | static const char kTestProperty[] = "RandomKey"; |
| 19 | static const char kTestValue[] = "random-value"; |
| 20 | static const char kOldValue[] = "old-value"; |
| 21 | string value = kOldValue; |
| 22 | DBusPropertiesMap props; |
| 23 | EXPECT_FALSE(DBusProperties::GetString(props, kTestProperty, &value)); |
| 24 | EXPECT_EQ(kOldValue, value); |
| 25 | props[kTestProperty].writer().append_string(kTestValue); |
| 26 | EXPECT_TRUE(DBusProperties::GetString(props, kTestProperty, &value)); |
| 27 | EXPECT_EQ(kTestValue, value); |
| 28 | } |
| 29 | |
| 30 | TEST_F(DBusPropertiesTest, GetUint32) { |
| 31 | static const char kTestProperty[] = "AKey"; |
| 32 | const uint32 kTestValue = 35; |
| 33 | const uint32 kOldValue = 74; |
| 34 | uint32 value = kOldValue; |
| 35 | DBusPropertiesMap props; |
| 36 | EXPECT_FALSE(DBusProperties::GetUint32(props, kTestProperty, &value)); |
| 37 | EXPECT_EQ(kOldValue, value); |
| 38 | props[kTestProperty].writer().append_uint32(kTestValue); |
| 39 | EXPECT_TRUE(DBusProperties::GetUint32(props, kTestProperty, &value)); |
| 40 | EXPECT_EQ(kTestValue, value); |
| 41 | } |
| 42 | |
Darin Petkov | ceb6817 | 2011-07-29 14:47:48 -0700 | [diff] [blame] | 43 | TEST_F(DBusPropertiesTest, GetUint16) { |
| 44 | static const char kTestProperty[] = "version"; |
| 45 | const uint16 kTestValue = 77; |
| 46 | const uint16 kOldValue = 88; |
| 47 | uint16 value = kOldValue; |
| 48 | DBusPropertiesMap props; |
| 49 | EXPECT_FALSE(DBusProperties::GetUint16(props, kTestProperty, &value)); |
| 50 | EXPECT_EQ(kOldValue, value); |
| 51 | props[kTestProperty].writer().append_uint16(kTestValue); |
| 52 | EXPECT_TRUE(DBusProperties::GetUint16(props, kTestProperty, &value)); |
| 53 | EXPECT_EQ(kTestValue, value); |
| 54 | } |
| 55 | |
Darin Petkov | e0a312e | 2011-07-20 13:45:28 -0700 | [diff] [blame] | 56 | } // namespace shill |