MCPcopy Create free account
hub / github.com/KhronosGroup/KTX-Software / expectSameTextureContent

Function expectSameTextureContent

tests/streamtests/streamtests.cc:282–332  ·  view source on GitHub ↗

Expects two textures to be equal in content (but not necessarily be the same texture).

Source from the content-addressed store, hash-verified

280
281/// Expects two textures to be equal in content (but not necessarily be the same texture).
282bool expectSameTextureContent(const ktxTexture* tex1, const ktxTexture* tex2)
283{
284 bool ok = true;
285#define EXPECT_EQ_OK(val1, val2) \
286 ok = ok && (val1) == (val2); \
287 EXPECT_EQ(val1, val2)
288
289 EXPECT_EQ_OK(tex1->classId, tex2->classId) << "Mismatched texture type (KTX1 or KTX2)";
290
291 EXPECT_EQ_OK(tex1->isArray, tex2->isArray) << "Both textures should [not] be array textures";
292 EXPECT_EQ_OK(tex1->isCubemap, tex2->isCubemap) << "Both textures should [not] be cubemap [arrays]";
293 EXPECT_EQ_OK(tex1->isCompressed, tex2->isCompressed) << "Both textures should [not] be compressed";
294
295 EXPECT_EQ_OK(tex1->baseWidth, tex2->baseWidth) << "Mismatched base width";
296 EXPECT_EQ_OK(tex1->baseHeight, tex2->baseHeight) << "Mismatched base height";
297 EXPECT_EQ_OK(tex1->baseDepth, tex2->baseDepth) << "Mismatched base depth";
298 EXPECT_EQ_OK(tex1->numDimensions, tex2->numDimensions) << "Mismatched # of texture dimensions";
299 EXPECT_EQ_OK(tex1->numLevels, tex2->numLevels) << "Mismatched # of texture levels";
300 EXPECT_EQ_OK(tex1->numLayers, tex2->numLayers) << "Mismatched # of texture layers";
301 EXPECT_EQ_OK(tex1->numFaces, tex2->numFaces) << "Mismatched # of texture faces";
302
303 EXPECT_EQ_OK(tex1->orientation.x, tex2->orientation.x) << "Mismatched X orientation";
304 EXPECT_EQ_OK(tex1->orientation.y, tex2->orientation.y) << "Mismatched Y orientation";
305 EXPECT_EQ_OK(tex1->orientation.z, tex2->orientation.z) << "Mismatched Z orientation";
306
307 EXPECT_EQ_OK(tex1->kvDataLen, tex2->kvDataLen) << "Mismatched K/V data length";
308 auto* e1 = ktxHashList_Next(tex1->kvDataHead);
309 auto* e2 = ktxHashList_Next(tex2->kvDataHead);
310 for(size_t i = 0; e1 && e2; e1 = ktxHashList_Next(e1), e2 = ktxHashList_Next(e2), i++)
311 {
312 unsigned int len1 = 0, len2 = 0;
313 {
314 char *key1 = nullptr, *key2 = nullptr;
315 (void)ktxHashListEntry_GetKey(e1, &len1, &key1);
316 (void)ktxHashListEntry_GetKey(e2, &len2, &key2);
317 EXPECT_EQ_OK(strncmp(key1, key2, std::min(len1, len2)), 0) << i << "th key mismatch";
318 }
319 {
320 void *val1 = nullptr, *val2 = nullptr;
321 (void)ktxHashListEntry_GetValue(e1, &len1, &val1);
322 (void)ktxHashListEntry_GetValue(e2, &len2, &val2);
323 EXPECT_EQ_OK(memcmp(val1, val2, std::min(len1, len2)), 0) << i << "th value mismatch";
324 }
325 }
326
327 EXPECT_EQ_OK(tex1->dataSize, tex2->dataSize) << "Mismatched image data size";
328 EXPECT_EQ_OK(memcmp(tex1->pData, tex2->pData, std::min(tex1->dataSize, tex2->dataSize)), 0) << "Mismatched image data";
329
330#undef EXPECT_EQ_OK
331 return ok;
332}
333
334// --- Tests ---
335

Callers 1

TEST_FFunction · 0.85

Calls 4

ktxHashList_NextFunction · 0.85
ktxHashListEntry_GetKeyFunction · 0.85
minFunction · 0.50

Tested by

no test coverage detected