software_version_test.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright (c) 2015-2016 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <sstream>
  15. #include <string>
  16. #include "gmock/gmock.h"
  17. #include "test/unit_spirv.h"
  18. namespace spvtools {
  19. namespace {
  20. using ::testing::AnyOf;
  21. using ::testing::Eq;
  22. using ::testing::Ge;
  23. using ::testing::StartsWith;
  24. void CheckFormOfHighLevelVersion(const std::string& version) {
  25. std::istringstream s(version);
  26. char v = 'x';
  27. int year = -1;
  28. char period = 'x';
  29. int index = -1;
  30. s >> v >> year >> period >> index;
  31. EXPECT_THAT(v, Eq('v'));
  32. EXPECT_THAT(year, Ge(2016));
  33. EXPECT_THAT(period, Eq('.'));
  34. EXPECT_THAT(index, Ge(0));
  35. EXPECT_TRUE(s.good() || s.eof());
  36. std::string rest;
  37. s >> rest;
  38. EXPECT_THAT(rest, AnyOf("", "-dev"));
  39. }
  40. TEST(SoftwareVersion, ShortIsCorrectForm) {
  41. SCOPED_TRACE("short form");
  42. CheckFormOfHighLevelVersion(spvSoftwareVersionString());
  43. }
  44. TEST(SoftwareVersion, DetailedIsCorrectForm) {
  45. const std::string detailed_version(spvSoftwareVersionDetailsString());
  46. EXPECT_THAT(detailed_version, StartsWith("SPIRV-Tools v"));
  47. // Parse the high level version.
  48. const std::string from_v =
  49. detailed_version.substr(detailed_version.find_first_of('v'));
  50. const size_t first_space_after_v_or_npos = from_v.find_first_of(' ');
  51. SCOPED_TRACE(detailed_version);
  52. CheckFormOfHighLevelVersion(from_v.substr(0, first_space_after_v_or_npos));
  53. // We don't actually care about what comes after the version number.
  54. }
  55. } // namespace
  56. } // namespace spvtools