Fix shill unittest build problem for gcc 4.7.
gcc 4.7 is more strict about type conversion in initilization list,
for example -
const char apple[] = {0xff, 0xfe};
The above compiles ok prior to gcc 4.7, but fails on gcc 4.7 with
-Wall -Werror. The reason is that 0xff is out of bound for (signed)
char type.
TEST=Built/tested using gcc 4.7
BUG=None
Change-Id: I597cac783954b856726494b757d69ddbc6c4436b
Reviewed-on: https://gerrit.chromium.org/gerrit/31908
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: Han Shen <shenhan@chromium.org>
Tested-by: Han Shen <shenhan@chromium.org>
diff --git a/device_info_unittest.cc b/device_info_unittest.cc
index fb9445f..48a336e 100644
--- a/device_info_unittest.cc
+++ b/device_info_unittest.cc
@@ -118,7 +118,7 @@
protected:
static const int kTestDeviceIndex;
static const char kTestDeviceName[];
- static const char kTestMACAddress[];
+ static const uint8_t kTestMACAddress[];
static const char kTestIPAddress0[];
static const int kTestIPAddressPrefix0;
static const char kTestIPAddress1[];
@@ -152,8 +152,8 @@
const int DeviceInfoTest::kTestDeviceIndex = 123456;
const char DeviceInfoTest::kTestDeviceName[] = "test-device";
-const char DeviceInfoTest::kTestMACAddress[] = {
- 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
+const uint8_t DeviceInfoTest::kTestMACAddress[] = {
+ 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
const char DeviceInfoTest::kTestIPAddress0[] = "192.168.1.1";
const int DeviceInfoTest::kTestIPAddressPrefix0 = 24;
const char DeviceInfoTest::kTestIPAddress1[] = "fe80::1aa9:5ff:abcd:1234";
@@ -766,7 +766,7 @@
SetSockets();
const int kFd = 99;
struct ifreq ifr;
- static char kMacAddress[] = {0x00, 0x01, 0x02, 0xaa, 0xbb, 0xcc};
+ static uint8_t kMacAddress[] = {0x00, 0x01, 0x02, 0xaa, 0xbb, 0xcc};
memcpy(ifr.ifr_hwaddr.sa_data, kMacAddress, sizeof(kMacAddress));
EXPECT_CALL(*mock_sockets_, Socket(PF_INET, SOCK_DGRAM, 0))
.WillOnce(Return(kFd));
diff --git a/dns_client_unittest.cc b/dns_client_unittest.cc
index 713487b..148f55e 100644
--- a/dns_client_unittest.cc
+++ b/dns_client_unittest.cc
@@ -44,7 +44,7 @@
const char kGoodServer[] = "8.8.8.8";
const char kBadServer[] = "10.9xx8.7";
const char kNetworkInterface[] = "eth0";
-char kReturnAddressList0[] = { 224, 0, 0, 1 };
+char kReturnAddressList0[] = { static_cast<char>(224), 0, 0, 1 };
char *kReturnAddressList[] = { kReturnAddressList0, NULL };
char kFakeAresChannelData = 0;
const ares_channel kAresChannel =
diff --git a/key_value_store_unittest.cc b/key_value_store_unittest.cc
index 3bcde8b..822d13d 100644
--- a/key_value_store_unittest.cc
+++ b/key_value_store_unittest.cc
@@ -27,8 +27,13 @@
EXPECT_EQ(kDefaultValue, store_.LookupBool(kKey, kDefaultValue));
store_.SetBool(kKey, kValue);
EXPECT_TRUE(store_.ContainsBool(kKey));
- EXPECT_EQ(kValue, store_.LookupBool(kKey, kDefaultValue));
- EXPECT_EQ(kValue, store_.GetBool(kKey));
+ // TODO: investigate if a newer version of gtest handles EXPECT_EQ for bools
+ // in a manner that gcc 4.7 is happy with. (Inproper conversion from "false"
+ // to "NULL".)
+ EXPECT_EQ(static_cast<int>(kValue),
+ static_cast<int>(store_.LookupBool(kKey, kDefaultValue)));
+ EXPECT_EQ(static_cast<int>(kValue),
+ static_cast<int>(store_.GetBool(kKey)));
}
TEST_F(KeyValueStoreTest, Int) {
diff --git a/link_monitor_unittest.cc b/link_monitor_unittest.cc
index de3dc61..2d481b9 100644
--- a/link_monitor_unittest.cc
+++ b/link_monitor_unittest.cc
@@ -114,7 +114,9 @@
}
void AdvanceTime(unsigned int time_ms) {
- struct timeval adv_time = { time_ms/1000, (time_ms % 1000) * 1000 };
+ struct timeval adv_time = {
+ static_cast<time_t>(time_ms/1000),
+ static_cast<time_t>((time_ms % 1000) * 1000) };
timeradd(&time_val_, &adv_time, &time_val_);
EXPECT_CALL(time_, GetTimeMonotonic(_))
.WillRepeatedly(DoAll(SetArgumentPointee<0>(time_val_), Return(0)));
diff --git a/property_store_unittest.cc b/property_store_unittest.cc
index 2256ff3..79239d0 100644
--- a/property_store_unittest.cc
+++ b/property_store_unittest.cc
@@ -123,7 +123,8 @@
PropertyStore store;
Error error;
TypeParam property;
- RegisterProperty(store, "some property", &property);
+ // |this| required due to two-phase lookup.
+ this->RegisterProperty(store, "some property", &property);
EXPECT_TRUE(store.ClearProperty("some property", &error));
}