// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/cros/network_library.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
TEST(WifiNetworkTest, DecodeNonAsciiSSID) {
// Sets network name.
{
std::string wifi_setname = "SSID TEST";
std::string wifi_setname_result = "SSID TEST";
WifiNetwork* wifi = new WifiNetwork("fw");
wifi->SetName(wifi_setname);
EXPECT_EQ(wifi->name(), wifi_setname_result);
delete wifi;
}
// Truncates invalid UTF-8
{
std::string wifi_setname2 = "SSID TEST \x01\xff!";
std::string wifi_setname2_result = "SSID TEST \xEF\xBF\xBD\xEF\xBF\xBD!";
WifiNetwork* wifi = new WifiNetwork("fw");
wifi->SetName(wifi_setname2);
EXPECT_EQ(wifi->name(), wifi_setname2_result);
delete wifi;
}
// UTF8 SSID
{
std::string wifi_utf8 = "UTF-8 \u3042\u3044\u3046";
std::string wifi_utf8_result = "UTF-8 \xE3\x81\x82\xE3\x81\x84\xE3\x81\x86";
WifiNetwork* wifi = new WifiNetwork("fw");
wifi->SetSsid(wifi_utf8);
EXPECT_EQ(wifi->name(), wifi_utf8_result);
delete wifi;
}
// latin1 SSID -> UTF8 SSID
{
std::string wifi_latin1 = "latin-1 \xc0\xcb\xcc\xd6\xfb";
std::string wifi_latin1_result = "latin-1 \u00c0\u00cb\u00cc\u00d6\u00fb";
WifiNetwork* wifi = new WifiNetwork("fw");
wifi->SetSsid(wifi_latin1);
EXPECT_EQ(wifi->name(), wifi_latin1_result);
delete wifi;
}
// Hex SSID
{
std::string wifi_hex = "5468697320697320484558205353494421";
std::string wifi_hex_result = "This is HEX SSID!";
WifiNetwork* wifi = new WifiNetwork("fw");
wifi->SetHexSsid(wifi_hex);
EXPECT_EQ(wifi->name(), wifi_hex_result);
delete wifi;
}
}
} // namespace chromeos