1 // Copyright (c) 2011 The Chromium 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 6 #include "chrome/browser/chromeos/cros/network_library.h" 7 #include "testing/gtest/include/gtest/gtest.h" 8 9 namespace chromeos { 10 11 TEST(WifiNetworkTest, DecodeNonAsciiSSID) { 12 13 // Sets network name. 14 { 15 std::string wifi_setname = "SSID TEST"; 16 std::string wifi_setname_result = "SSID TEST"; 17 WifiNetwork* wifi = new WifiNetwork("fw"); 18 wifi->SetName(wifi_setname); 19 EXPECT_EQ(wifi->name(), wifi_setname_result); 20 delete wifi; 21 } 22 23 // Truncates invalid UTF-8 24 { 25 std::string wifi_setname2 = "SSID TEST \x01\xff!"; 26 std::string wifi_setname2_result = "SSID TEST \xEF\xBF\xBD\xEF\xBF\xBD!"; 27 WifiNetwork* wifi = new WifiNetwork("fw"); 28 wifi->SetName(wifi_setname2); 29 EXPECT_EQ(wifi->name(), wifi_setname2_result); 30 delete wifi; 31 } 32 33 // UTF8 SSID 34 { 35 std::string wifi_utf8 = "UTF-8 \u3042\u3044\u3046"; 36 std::string wifi_utf8_result = "UTF-8 \xE3\x81\x82\xE3\x81\x84\xE3\x81\x86"; 37 WifiNetwork* wifi = new WifiNetwork("fw"); 38 wifi->SetSsid(wifi_utf8); 39 EXPECT_EQ(wifi->name(), wifi_utf8_result); 40 delete wifi; 41 } 42 43 // latin1 SSID -> UTF8 SSID 44 { 45 std::string wifi_latin1 = "latin-1 \xc0\xcb\xcc\xd6\xfb"; 46 std::string wifi_latin1_result = "latin-1 \u00c0\u00cb\u00cc\u00d6\u00fb"; 47 WifiNetwork* wifi = new WifiNetwork("fw"); 48 wifi->SetSsid(wifi_latin1); 49 EXPECT_EQ(wifi->name(), wifi_latin1_result); 50 delete wifi; 51 } 52 53 // Hex SSID 54 { 55 std::string wifi_hex = "5468697320697320484558205353494421"; 56 std::string wifi_hex_result = "This is HEX SSID!"; 57 WifiNetwork* wifi = new WifiNetwork("fw"); 58 wifi->SetHexSsid(wifi_hex); 59 EXPECT_EQ(wifi->name(), wifi_hex_result); 60 delete wifi; 61 } 62 } 63 } // namespace chromeos 64