unit_spirv.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright (c) 2015-2016 The Khronos Group 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 "test/unit_spirv.h"
  15. #include "gmock/gmock.h"
  16. #include "source/util/string_utils.h"
  17. #include "test/test_fixture.h"
  18. namespace spvtools {
  19. namespace {
  20. using utils::MakeVector;
  21. using ::testing::Eq;
  22. using Words = std::vector<uint32_t>;
  23. TEST(MakeVector, Samples) {
  24. EXPECT_THAT(MakeVector(""), Eq(Words{0}));
  25. EXPECT_THAT(MakeVector("a"), Eq(Words{0x0061}));
  26. EXPECT_THAT(MakeVector("ab"), Eq(Words{0x006261}));
  27. EXPECT_THAT(MakeVector("abc"), Eq(Words{0x00636261}));
  28. EXPECT_THAT(MakeVector("abcd"), Eq(Words{0x64636261, 0x00}));
  29. EXPECT_THAT(MakeVector("abcde"), Eq(Words{0x64636261, 0x0065}));
  30. }
  31. TEST(WordVectorPrintTo, PreservesFlagsAndFill) {
  32. std::stringstream s;
  33. s << std::setw(4) << std::oct << std::setfill('x') << 8 << " ";
  34. spvtest::PrintTo(spvtest::WordVector({10, 16}), &s);
  35. // The octal setting and fill character should be preserved
  36. // from before the PrintTo.
  37. // Width is reset after each emission of a regular scalar type.
  38. // So set it explicitly again.
  39. s << std::setw(4) << 9;
  40. EXPECT_THAT(s.str(), Eq("xx10 0x0000000a 0x00000010 xx11"));
  41. }
  42. } // namespace
  43. } // namespace spvtools