Chris Masone | 34af218 | 2011-08-22 11:59:36 -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 "shill/wifi_service.h" |
| 6 | |
| 7 | #include <string> |
| 8 | #include <vector> |
| 9 | |
| 10 | #include <base/string_util.h> |
| 11 | #include <chromeos/dbus/service_constants.h> |
| 12 | #include <gmock/gmock.h> |
| 13 | #include <gtest/gtest.h> |
| 14 | |
| 15 | #include "shill/manager.h" |
| 16 | #include "shill/mock_adaptors.h" |
| 17 | #include "shill/mock_control.h" |
| 18 | #include "shill/mock_service.h" |
| 19 | #include "shill/mock_store.h" |
| 20 | #include "shill/property_store_unittest.h" |
| 21 | #include "shill/shill_event.h" |
| 22 | #include "shill/wifi.h" |
| 23 | |
| 24 | using std::string; |
| 25 | using std::vector; |
| 26 | |
| 27 | namespace shill { |
| 28 | |
| 29 | class WiFiServiceTest : public PropertyStoreTest { |
| 30 | public: |
| 31 | WiFiServiceTest() {} |
| 32 | virtual ~WiFiServiceTest() {} |
| 33 | }; |
| 34 | |
| 35 | TEST_F(WiFiServiceTest, StorageId) { |
| 36 | vector<uint8_t> ssid(5, 0); |
| 37 | ssid.push_back(0xff); |
| 38 | |
| 39 | WiFiServiceRefPtr wifi = new WiFiService(&control_interface_, |
| 40 | &dispatcher_, |
| 41 | &manager_, |
| 42 | NULL, |
| 43 | ssid, |
| 44 | flimflam::kModeManaged, |
| 45 | "none"); |
| 46 | static const char fake_mac[] = "AaBBcCDDeeFF"; |
| 47 | string id = wifi->GetStorageIdentifier(fake_mac); |
| 48 | for (uint i = 0; i < id.length(); ++i) { |
| 49 | EXPECT_TRUE(id[i] == '_' || |
| 50 | isxdigit(id[i]) || |
| 51 | (isalpha(id[i]) && islower(id[i]))); |
| 52 | } |
| 53 | size_t mac_pos = id.find(StringToLowerASCII(string(fake_mac))); |
| 54 | EXPECT_NE(mac_pos, string::npos); |
| 55 | EXPECT_NE(id.find(string(flimflam::kModeManaged), mac_pos), string::npos); |
| 56 | } |
| 57 | |
| 58 | } // namespace shill |