blob: 631ae6a568b09542641759434df2370bb60b1a0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
// This file is part of the 64k demo project.
// It tests the asset manager's ability to retrieve packed data.
// Verifies data integrity and size reporting.
#if defined(USE_TEST_ASSETS)
#include "test_assets.h"
#else
#include "generated/assets.h"
#endif /* defined(USE_TEST_ASSETS) */
#include "util/asset_manager_utils.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
int main() {
printf("Running AssetManager test...\n");
// Test WGSL asset
size_t size = 0;
const uint8_t* data = GetAsset(AssetId::ASSET_TEST_WGSL, &size);
assert(data != nullptr);
assert(size > 0);
assert(GetAssetType(AssetId::ASSET_TEST_WGSL) == AssetType::WGSL);
printf("WGSL asset test: SUCCESS\n");
// Test SPEC asset
data = GetAsset(AssetId::ASSET_TEST_SPEC, &size);
assert(data != nullptr);
assert(size > 0);
assert(GetAssetType(AssetId::ASSET_TEST_SPEC) == AssetType::SPEC);
printf("SPEC asset test: SUCCESS\n");
// Test MESH asset
MeshAsset mesh = GetMeshAsset(AssetId::ASSET_TEST_MESH);
assert(mesh.vertices != nullptr);
assert(mesh.num_vertices > 0);
assert(mesh.indices != nullptr);
assert(mesh.num_indices > 0);
assert(GetAssetType(AssetId::ASSET_TEST_MESH) == AssetType::MESH);
printf("MESH asset test: SUCCESS\n");
// Test TEXTURE asset
TextureAsset tex = GetTextureAsset(AssetId::ASSET_TEST_TEXTURE);
assert(tex.pixels != nullptr);
assert(tex.width > 0);
assert(tex.height > 0);
assert(GetAssetType(AssetId::ASSET_TEST_TEXTURE) == AssetType::TEXTURE);
printf("TEXTURE asset test: SUCCESS\n");
// Test MP3 asset
data = GetAsset(AssetId::ASSET_TEST_MP3, &size);
assert(data != nullptr);
assert(size > 0);
assert(GetAssetType(AssetId::ASSET_TEST_MP3) == AssetType::MP3);
printf("MP3 asset test: SUCCESS\n");
// Test PROC asset
data = GetAsset(AssetId::ASSET_TEST_PROC, &size);
assert(data != nullptr);
assert(size > 0);
assert(GetAssetType(AssetId::ASSET_TEST_PROC) == AssetType::PROC);
DropAsset(AssetId::ASSET_TEST_PROC, data);
printf("PROC asset test: SUCCESS\n");
// Test caching: request the same asset again and verify pointer is identical
const uint8_t* data1 = GetAsset(AssetId::ASSET_TEST_WGSL, &size);
const uint8_t* data2 = GetAsset(AssetId::ASSET_TEST_WGSL, &size);
assert(data1 == data2);
printf("Asset caching test: SUCCESS\n");
// Test ASSET_LAST_ID - should not return a valid asset
const uint8_t* last_id_data = GetAsset(AssetId::ASSET_LAST_ID, &size);
assert(last_id_data == nullptr);
printf("ASSET_LAST_ID test: SUCCESS\n");
printf("\n--- ALL ASSET TESTS PASSED ---\n");
return 0;
}
|