test_refparams_v1.tc¶
test_refparams_v1.tc — reference parameters (Phase A v1) probe
// =================================================================
// test_refparams_v1.tc — reference parameters (Phase A v1) probe
// =================================================================
// Test 1: classic swap
void swap(int& a, int& b) {
int tmp = a;
a = b;
b = tmp;
}
void test_swap() {
int x = 5;
int y = 7;
swap(x, y);
addLog("test_swap: x=%d y=%d (expect 7,5)", x, y);
}
// Test 2: increment + multi-out
void parse_pair(int input, int& low, int& high) {
low = input & 0xFF;
high = (input >> 8) & 0xFF;
}
void test_multi_out() {
int hi = 0;
int lo = 0;
parse_pair(0xABCD, lo, hi);
addLog("test_multi_out: lo=0x%02x hi=0x%02x (expect cd,ab)", lo, hi);
}
// Test 3: compound assignment on ref
void inc_by(int& n, int amount) {
n += amount;
}
void test_compound() {
int counter = 10;
inc_by(counter, 5);
inc_by(counter, 5);
inc_by(counter, 5);
addLog("test_compound: counter=%d (expect 25)", counter);
}
// Test 4: globals as ref args
int g_count = 0;
int g_total = 0;
void accumulate(int& count, int& total, int sample) {
count += 1;
total += sample;
}
void test_globals() {
accumulate(g_count, g_total, 100);
accumulate(g_count, g_total, 200);
accumulate(g_count, g_total, 300);
addLog("test_globals: g_count=%d g_total=%d (expect 3,600)", g_count, g_total);
}
int main() {
addLog("=== refparams v1 probe start ===");
test_swap();
test_multi_out();
test_compound();
test_globals();
addLog("=== refparams v1 probe end ===");
return 0;
}