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