text_destroy_test.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. namespace spvtools {
  16. namespace {
  17. TEST(TextDestroy, DestroyNull) { spvBinaryDestroy(nullptr); }
  18. TEST(TextDestroy, Default) {
  19. spv_context context = spvContextCreate(SPV_ENV_UNIVERSAL_1_0);
  20. char textStr[] = R"(
  21. OpSource OpenCL_C 12
  22. OpMemoryModel Physical64 OpenCL
  23. OpSourceExtension "PlaceholderExtensionName"
  24. OpEntryPoint Kernel %0 ""
  25. OpExecutionMode %0 LocalSizeHint 1 1 1
  26. %1 = OpTypeVoid
  27. %2 = OpTypeBool
  28. %3 = OpTypeInt 8 0
  29. %4 = OpTypeInt 8 1
  30. %5 = OpTypeInt 16 0
  31. %6 = OpTypeInt 16 1
  32. %7 = OpTypeInt 32 0
  33. %8 = OpTypeInt 32 1
  34. %9 = OpTypeInt 64 0
  35. %10 = OpTypeInt 64 1
  36. %11 = OpTypeFloat 16
  37. %12 = OpTypeFloat 32
  38. %13 = OpTypeFloat 64
  39. %14 = OpTypeVector %3 2
  40. )";
  41. spv_binary binary = nullptr;
  42. spv_diagnostic diagnostic = nullptr;
  43. EXPECT_EQ(SPV_SUCCESS, spvTextToBinary(context, textStr, strlen(textStr),
  44. &binary, &diagnostic));
  45. EXPECT_NE(nullptr, binary);
  46. EXPECT_NE(nullptr, binary->code);
  47. EXPECT_NE(0u, binary->wordCount);
  48. if (diagnostic) {
  49. spvDiagnosticPrint(diagnostic);
  50. ASSERT_TRUE(false);
  51. }
  52. spv_text resultText = nullptr;
  53. EXPECT_EQ(SPV_SUCCESS,
  54. spvBinaryToText(context, binary->code, binary->wordCount, 0,
  55. &resultText, &diagnostic));
  56. spvBinaryDestroy(binary);
  57. if (diagnostic) {
  58. spvDiagnosticPrint(diagnostic);
  59. spvDiagnosticDestroy(diagnostic);
  60. ASSERT_TRUE(false);
  61. }
  62. EXPECT_NE(nullptr, resultText->str);
  63. EXPECT_NE(0u, resultText->length);
  64. spvTextDestroy(resultText);
  65. spvContextDestroy(context);
  66. }
  67. } // namespace
  68. } // namespace spvtools