|
| 1 | +// unit-test-byte-encode.cpp |
| 2 | + |
| 3 | +#include "../../slang.h" |
| 4 | + |
| 5 | +#include <stdio.h> |
| 6 | +#include <stdlib.h> |
| 7 | + |
| 8 | +#include "test-context.h" |
| 9 | + |
| 10 | +using namespace Slang; |
| 11 | + |
| 12 | +static void findTypeByNameTest() |
| 13 | +{ |
| 14 | + const char* testSource = |
| 15 | + "struct TestStruct {" |
| 16 | + " int member0;" |
| 17 | + " Texture2D texture1;" |
| 18 | + "};"; |
| 19 | + auto session = spCreateSession(); |
| 20 | + auto request = spCreateCompileRequest(session); |
| 21 | + spAddCodeGenTarget(request, SLANG_DXBC); |
| 22 | + int tuIndex = spAddTranslationUnit(request, SLANG_SOURCE_LANGUAGE_SLANG, "tu1"); |
| 23 | + spAddTranslationUnitSourceString(request, tuIndex, "internalFile", testSource); |
| 24 | + spCompile(request); |
| 25 | + |
| 26 | + auto testBody = [&]() |
| 27 | + { |
| 28 | + auto reflection = slang::ShaderReflection::get(request); |
| 29 | + auto testStruct = reflection->findTypeByName("TestStruct"); |
| 30 | + SLANG_CHECK_ABORT(testStruct->getFieldCount() == 2); |
| 31 | + auto field0Name = testStruct->getFieldByIndex(0)->getName(); |
| 32 | + SLANG_CHECK_ABORT(field0Name != nullptr && strcmp(field0Name, "member0") == 0); |
| 33 | + auto field1Name = testStruct->getFieldByIndex(1)->getName(); |
| 34 | + SLANG_CHECK_ABORT(field1Name != nullptr && strcmp(field1Name, "texture1") == 0); |
| 35 | + |
| 36 | + auto intType = reflection->findTypeByName("int"); |
| 37 | + auto intTypeName = intType->getName(); |
| 38 | + SLANG_CHECK_ABORT(intTypeName && strcmp(intTypeName, "int") == 0); |
| 39 | + |
| 40 | + auto paramBlockType = reflection->findTypeByName("ParameterBlock<TestStruct>"); |
| 41 | + SLANG_CHECK_ABORT(paramBlockType != nullptr); |
| 42 | + auto paramBlockTypeName = paramBlockType->getName(); |
| 43 | + SLANG_CHECK_ABORT(paramBlockTypeName && strcmp(paramBlockTypeName, "ParameterBlock") == 0); |
| 44 | + auto paramBlockElementType = paramBlockType->getElementType(); |
| 45 | + SLANG_CHECK_ABORT(paramBlockElementType != nullptr); |
| 46 | + auto paramBlockElementTypeName = paramBlockElementType->getName(); |
| 47 | + SLANG_CHECK_ABORT(paramBlockElementTypeName && strcmp(paramBlockElementTypeName, "TestStruct") == 0); |
| 48 | + }; |
| 49 | + |
| 50 | + testBody(); |
| 51 | + |
| 52 | + spDestroyCompileRequest(request); |
| 53 | + spDestroySession(session); |
| 54 | +} |
| 55 | + |
| 56 | +SLANG_UNIT_TEST("findTypeByName", findTypeByNameTest); |
0 commit comments