Skip to content

Commit

Permalink
Add tests for TypeSpec
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Jan 31, 2024
1 parent 027ece6 commit b611631
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/emit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(SOURCES
methoddef.cpp
standalonesig.cpp
memberref.cpp
typespec.cpp
)

set(HEADERS emit.hpp)
Expand Down
23 changes: 23 additions & 0 deletions test/emit/typespec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "emit.hpp"
#include <array>
#include <vector>
#include <gmock/gmock.h>

TEST(TypeSpec, Define)
{
dncp::com_ptr<IMetaDataEmit> emit;
ASSERT_NO_FATAL_FAILURE(CreateEmit(emit));
mdTypeSpec spec;
std::array<uint8_t, 3> signature = {0x01, 0x02, 0x03};
ASSERT_EQ(S_OK, emit->GetTokenFromTypeSpec(signature.data(), (ULONG)signature.size(), &spec));
ASSERT_EQ(1, RidFromToken(spec));
ASSERT_EQ(mdtTypeSpec, TypeFromToken(spec));

dncp::com_ptr<IMetaDataImport> import;
ASSERT_EQ(S_OK, emit->QueryInterface(IID_IMetaDataImport, (void**)&import));

PCCOR_SIGNATURE sigBlob;
ULONG sigBlobLength;
ASSERT_EQ(S_OK, import->GetTypeSpecFromToken(spec, &sigBlob, &sigBlobLength));
EXPECT_THAT(std::vector(sigBlob, sigBlob + sigBlobLength), testing::ContainerEq(std::vector(signature.begin(), signature.end())));
}

0 comments on commit b611631

Please sign in to comment.