summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/version_loader_unittest.cc
blob: 4f2acebe9e65f1a2df3d1bc6662dfefbc39c9992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2010 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/version_loader.h"

#include <string>

#include "testing/gtest/include/gtest/gtest.h"

namespace chromeos {

typedef testing::Test VersionLoaderTest;

static const char kTest1[] =
    "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3\nFOO=BAR";
static const char kTest2[] = "DIST_ID=1\nCHROMEOS_RELEASE_DESCRIPTION=0.2.3.3";
static const char kTest3[] = "CHROMEOS_RELEASE_DESCRIPTION=\"0.2.3.3\"";
static const char kTest4[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\"\"";
static const char kTest5[] = "CHROMEOS_RELEASE_DESCRIPTION=\"\"";

static const char kTest6[] =
    "CHROMEOS_RELEASE_DESCRIPTION=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3\nFOO=BAR";
static const char kTest7[] = "DIST_ID=1\nCHROMEOS_RELEASE_VERSION=0.2.3.3";
static const char kTest8[] = "CHROMEOS_RELEASE_VERSION=\"0.2.3.3\"";
static const char kTest9[] = "CHROMEOS_RELEASE_VERSION=\"\"";

TEST_F(VersionLoaderTest, ParseFullVersion) {
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest1,
                                        VersionLoader::kFullVersionPrefix));
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest2,
                                        VersionLoader::kFullVersionPrefix));
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest3,
                                        VersionLoader::kFullVersionPrefix));
  EXPECT_EQ("\"",
            VersionLoader::ParseVersion(kTest4,
                                        VersionLoader::kFullVersionPrefix));
  EXPECT_EQ(std::string(),
            VersionLoader::ParseVersion(kTest5,
                                        VersionLoader::kFullVersionPrefix));
  EXPECT_EQ(std::string(),
            VersionLoader::ParseVersion(std::string(),
                                        VersionLoader::kFullVersionPrefix));
}

TEST_F(VersionLoaderTest, ParseVersion) {
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest6,
                                        VersionLoader::kVersionPrefix));
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest7,
                                        VersionLoader::kVersionPrefix));
  EXPECT_EQ("0.2.3.3",
            VersionLoader::ParseVersion(kTest8,
                                        VersionLoader::kVersionPrefix));
  EXPECT_EQ(std::string(),
            VersionLoader::ParseVersion(kTest9,
                                        VersionLoader::kFullVersionPrefix));
}

}  // namespace chromeos