1// Copyright (c) 2010 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#include "chrome/browser/chromeos/version_loader.h" 6 7#include <string> 8 9#include "testing/gtest/include/gtest/gtest.h" 10 11namespace chromeos { 12 13typedef testing::Test VersionLoaderTest; 14 15static const char kTest1[] = 16 "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3\nFOO=BAR"; 17static const char kTest2[] = "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3"; 18static const char kTest3[] = "CHROMEOS_RELEASE_DESCRIPTION=\"0.2.3.3\""; 19static const char kTest4[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\"\""; 20static const char kTest5[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\""; 21 22static const char kTest6[] = 23 "CHROMEOS_RELEASE_DESCRIPTION=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3\nFOO=BAR"; 24static const char kTest7[] = "DIST_ID=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3"; 25static const char kTest8[] = "CHROMEOS_RELEASE_VERSION=\"0.2.3.3\""; 26static const char kTest9[] = "CHROMEOS_RELEASE_VERSION=\"\""; 27 28static const char kTest10[] = "vendor | FOO"; 29static const char kTest11[] = "firmware | FOO"; 30static const char kTest12[] = "firmware | FOO"; 31static const char kTest13[] = "version | 0.2.3.3"; 32static const char kTest14[] = "version | 0.2.3.3"; 33static const char kTest15[] = "version 0.2.3.3"; 34 35TEST_F(VersionLoaderTest, ParseFullVersion) { 36 EXPECT_EQ("0.2.3.3", 37 VersionLoader::ParseVersion(kTest1, 38 VersionLoader::kFullVersionPrefix)); 39 EXPECT_EQ("0.2.3.3", 40 VersionLoader::ParseVersion(kTest2, 41 VersionLoader::kFullVersionPrefix)); 42 EXPECT_EQ("0.2.3.3", 43 VersionLoader::ParseVersion(kTest3, 44 VersionLoader::kFullVersionPrefix)); 45 EXPECT_EQ("\"", 46 VersionLoader::ParseVersion(kTest4, 47 VersionLoader::kFullVersionPrefix)); 48 EXPECT_EQ(std::string(), 49 VersionLoader::ParseVersion(kTest5, 50 VersionLoader::kFullVersionPrefix)); 51 EXPECT_EQ(std::string(), 52 VersionLoader::ParseVersion(std::string(), 53 VersionLoader::kFullVersionPrefix)); 54} 55 56TEST_F(VersionLoaderTest, ParseVersion) { 57 EXPECT_EQ("0.2.3.3", 58 VersionLoader::ParseVersion(kTest6, 59 VersionLoader::kVersionPrefix)); 60 EXPECT_EQ("0.2.3.3", 61 VersionLoader::ParseVersion(kTest7, 62 VersionLoader::kVersionPrefix)); 63 EXPECT_EQ("0.2.3.3", 64 VersionLoader::ParseVersion(kTest8, 65 VersionLoader::kVersionPrefix)); 66 EXPECT_EQ(std::string(), 67 VersionLoader::ParseVersion(kTest9, 68 VersionLoader::kFullVersionPrefix)); 69} 70 71TEST_F(VersionLoaderTest, ParseFirmware) { 72 EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest10)); 73 EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest11)); 74 EXPECT_EQ(std::string(), VersionLoader::ParseFirmware(kTest12)); 75 EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest13)); 76 EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest14)); 77 EXPECT_EQ("0.2.3.3", VersionLoader::ParseFirmware(kTest15)); 78} 79 80} // namespace chromeos 81