keymaster_configuration_test.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <gtest/gtest.h>
  17. #include <keymaster/keymaster_configuration.h>
  18. #ifdef HOST_BUILD
  19. extern "C" {
  20. int __android_log_print(int prio, const char* tag, const char* fmt);
  21. int __android_log_print(int prio, const char* tag, const char* fmt) {
  22. (void)prio, (void)tag, (void)fmt;
  23. std::cout << fmt << std::endl;
  24. return 0;
  25. }
  26. } // extern "C"
  27. #endif // HOST_BUILD
  28. namespace keymaster {
  29. namespace test {
  30. TEST(VersionParsingTest, Full) {
  31. EXPECT_EQ(612334U, GetOsVersion("61.23.34"));
  32. EXPECT_EQ(680000U, GetOsVersion("681.23.24"));
  33. EXPECT_EQ(682300U, GetOsVersion("68.231.24"));
  34. EXPECT_EQ(682324U, GetOsVersion("68.23.241"));
  35. EXPECT_EQ(60102U, GetOsVersion("6.1.2-extrajunk"));
  36. EXPECT_EQ(0U, GetOsVersion("extra6.1.2"));
  37. }
  38. TEST(VersionParsingTest, FullWithExtraChars) {}
  39. TEST(VersionParsingTest, MajorOnly) {
  40. EXPECT_EQ(60000U, GetOsVersion("6"));
  41. EXPECT_EQ(680000U, GetOsVersion("68"));
  42. EXPECT_EQ(680000U, GetOsVersion("681"));
  43. EXPECT_EQ(60000U, GetOsVersion("6.junk"));
  44. }
  45. TEST(VersionParsingTest, MajorMinorOnly) {
  46. EXPECT_EQ(60100U, GetOsVersion("6.1"));
  47. EXPECT_EQ(60100U, GetOsVersion("6.1junk"));
  48. }
  49. TEST(PatchLevelParsingTest, Full) {
  50. EXPECT_EQ(201603U, GetOsPatchlevel("2016-03-23"));
  51. EXPECT_EQ(0U, GetOsPatchlevel("2016-13-23"));
  52. EXPECT_EQ(0U, GetOsPatchlevel("2016-03"));
  53. EXPECT_EQ(0U, GetOsPatchlevel("2016-3-23"));
  54. EXPECT_EQ(0U, GetOsPatchlevel("2016-03-23r"));
  55. EXPECT_EQ(0U, GetOsPatchlevel("r2016-03-23"));
  56. }
  57. } // namespace test
  58. } // namespace keymaster