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