summaryrefslogtreecommitdiff
path: root/unit_test/keymaster_configuration_test.cpp (plain)
blob: 81e9598e380ac5eb6fe65a27959622e1b31eaafb
1/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <keymaster/keymaster_configuration.h>
20
21#ifdef HOST_BUILD
22extern "C" {
23int __android_log_print(int prio, const char* tag, const char* fmt);
24int __android_log_print(int prio, const char* tag, const char* fmt) {
25 (void)prio, (void)tag, (void)fmt;
26 std::cout << fmt << std::endl;
27 return 0;
28}
29} // extern "C"
30#endif // HOST_BUILD
31
32namespace keymaster {
33namespace test {
34
35TEST(VersionParsingTest, Full) {
36 EXPECT_EQ(612334U, GetOsVersion("61.23.34"));
37 EXPECT_EQ(680000U, GetOsVersion("681.23.24"));
38 EXPECT_EQ(682300U, GetOsVersion("68.231.24"));
39 EXPECT_EQ(682324U, GetOsVersion("68.23.241"));
40 EXPECT_EQ(60102U, GetOsVersion("6.1.2-extrajunk"));
41 EXPECT_EQ(0U, GetOsVersion("extra6.1.2"));
42}
43
44TEST(VersionParsingTest, FullWithExtraChars) {}
45
46TEST(VersionParsingTest, MajorOnly) {
47 EXPECT_EQ(60000U, GetOsVersion("6"));
48 EXPECT_EQ(680000U, GetOsVersion("68"));
49 EXPECT_EQ(680000U, GetOsVersion("681"));
50 EXPECT_EQ(60000U, GetOsVersion("6.junk"));
51}
52
53TEST(VersionParsingTest, MajorMinorOnly) {
54 EXPECT_EQ(60100U, GetOsVersion("6.1"));
55 EXPECT_EQ(60100U, GetOsVersion("6.1junk"));
56}
57
58TEST(PatchLevelParsingTest, Full) {
59 EXPECT_EQ(201603U, GetOsPatchlevel("2016-03-23"));
60 EXPECT_EQ(0U, GetOsPatchlevel("2016-13-23"));
61 EXPECT_EQ(0U, GetOsPatchlevel("2016-03"));
62 EXPECT_EQ(0U, GetOsPatchlevel("2016-3-23"));
63 EXPECT_EQ(0U, GetOsPatchlevel("2016-03-23r"));
64 EXPECT_EQ(0U, GetOsPatchlevel("r2016-03-23"));
65}
66
67} // namespace test
68} // namespace keymaster
69