]> FriiDump Source - friidump.git/blob - tests/test_hlds_e7_profiles.c
Harden GCC-4243N A102 HLDS E7 profile
[friidump.git] / tests / test_hlds_e7_profiles.c
1 #include "dvd_drive.h"
2
3 #include <stdio.h>
4 #include <string.h>
5
6 typedef struct {
7     const char *label;
8     const char *vendor;
9     const char *product;
10     const char *revision;
11     bool exact;
12     u_int32_t type;
13     u_int32_t cdb;
14     u_int32_t gate;
15     u_int32_t blocks;
16     int method;
17     const char *record_id;
18     const char *tokens;
19 } profile_case;
20
21 static int check_case(const profile_case *test) {
22     dvd_hlds_e7_profile_info info;
23     bool exact = dvd_lookup_hlds_e7_profile(
24         test->vendor,
25         test->product,
26         test->revision,
27         &info);
28     u_int32_t detected = dvd_detect_hlds_e7_type_for_identity(
29         test->vendor,
30         test->product,
31         test->revision);
32
33     if (exact != test->exact) {
34         fprintf(stderr,
35             "FAIL: %s exact=%d expected=%d\n",
36             test->label, (int) exact, (int) test->exact);
37         return 0;
38     }
39
40     if (detected != test->type) {
41         fprintf(stderr,
42             "FAIL: %s type=%u expected=%u\n",
43             test->label, detected, test->type);
44         return 0;
45     }
46
47     if (!exact) {
48         printf("PASS: %s legacy type=%u\n", test->label, detected);
49         return 1;
50     }
51
52     if (
53         info.type != test->type ||
54         info.static_cdb_base != test->cdb ||
55         info.static_gate != test->gate ||
56         info.mem_blocks != test->blocks ||
57         info.preferred_method != test->method ||
58         !info.tokens ||
59         strcmp(info.tokens, test->tokens) != 0 ||
60         !info.record_id ||
61         strcmp(info.record_id, test->record_id) != 0
62     ) {
63         fprintf(stderr,
64             "FAIL: %s type=%u cdb=0x%03x gate=0x%08x "
65             "blocks=%u method=%d tokens=%s record=%s\n",
66             test->label,
67             info.type,
68             info.static_cdb_base,
69             info.static_gate,
70             info.mem_blocks,
71             info.preferred_method,
72             info.tokens ? info.tokens : "(null)",
73             info.record_id ? info.record_id : "(null)");
74         return 0;
75     }
76
77     printf("PASS: %s exact cdb=0x%03x gate=0x%08x\n",
78         test->label, info.static_cdb_base, info.static_gate);
79     return 1;
80 }
81
82 int main(void) {
83     static const profile_case cases[] = {
84         {
85             "A102 live inquiry alias",
86             "HL-DT-ST", "CDRW/DVD GCC4243", "A102",
87             true, 3, 0x880U, 0x9003731dU, 5, 8,
88             "hybrid_identity_v3:stage5b_0439",
89             "HL;IT;RPC;RPC_JCS3;RPC_SUFFIX"
90         },
91         {
92             "A102 canonical alias",
93             "HL-DT-ST", "GCC-4243N", "a102",
94             true, 3, 0x880U, 0x9003731dU, 5, 8,
95             "hybrid_identity_v3:stage5b_0439",
96             "HL;IT;RPC;RPC_JCS3;RPC_SUFFIX"
97         },
98         {
99             "B101 live inquiry alias",
100             "HL-DT-ST", "CDRW/DVD GCC4244", "B101",
101             true, 3, 0x894U, 0x900386d2U, 5, 8,
102             "hybrid_identity_v3:stage5b_0426",
103             "HL;IT;RPC;RPC_JCS3;RPC_SUFFIX"
104         },
105         {
106             "B101 canonical alias",
107             "HL-DT-ST", "GCC-4244N", "b101",
108             true, 3, 0x894U, 0x900386d2U, 5, 8,
109             "hybrid_identity_v3:stage5b_0426",
110             "HL;IT;RPC;RPC_JCS3;RPC_SUFFIX"
111         },
112         {
113             "A101 existing canonical profile",
114             "HL-DT-ST", "GCC-4241N", "A101",
115             true, 21, 0x85cU, 0x900356b7U, 1, 8,
116             "stage5b_0064",
117             "HL;IT;RPC;RPC_JCS3;RPC_SUFFIX"
118         },
119         {
120             "GDR-8050L 0012 hybrid operating identity",
121             "HL-DT-ST", "DVD-ROM GDR8050L", "0012",
122             true, 44, 0x5d0U, 0x90026160U, 1, 8,
123             "hybrid_identity_v3:gdr8050l_0012",
124             "HL;IT;RPC;RPC_JD4_SPACE;RPC_SUFFIX"
125         },
126         {
127             "GDR-8050L 0L23 has no false exact metadata",
128             "HL-DT-ST", "DVD-ROM GDR8050L", "0L23",
129             false, 44, 0, 0, 0, 0, NULL, NULL
130         },
131         {
132             "A103 conservative Type3 fallback",
133             "HL-DT-ST", "CDRW/DVD GCC4243", "A103",
134             false, 3, 0, 0, 0, 0, NULL, NULL
135         },
136         {
137             "B102 conservative Type3 fallback",
138             "HL-DT-ST", "CDRW/DVD GCC4244", "B102",
139             false, 3, 0, 0, 0, 0, NULL, NULL
140         },
141         {
142             "non-HL vendor rejected",
143             "NOT-HL", "CDRW/DVD GCC4243", "A102",
144             false, 0, 0, 0, 0, 0, NULL, NULL
145         }
146     };
147     size_t i;
148     int ok = 1;
149
150     for (i = 0; i < sizeof(cases) / sizeof(cases[0]); i++)
151         ok &= check_case(&cases[i]);
152
153     if (!ok)
154         return 1;
155
156     printf("HLDS E7 PROFILE SELECTION TESTS: PASS\n");
157     return 0;
158 }