File: test-const_str_hash.c

package info (click to toggle)
rtpengine 13.5.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: ansic: 86,775; perl: 59,422; python: 3,193; sh: 1,037; makefile: 687; asm: 211
file content (39 lines) | stat: -rw-r--r-- 694 bytes parent folder | download
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
#include <stdlib.h>
#include <stdio.h>
#include "str.h"

static int test_hash(char *p) {
	str s;
	s = STR(p);
	switch (__csh_lookup(&s)) {
		case CSH_LOOKUP("one"):
			return 1;
		case CSH_LOOKUP("two"):
			return 2;
		case CSH_LOOKUP("dashed-string"):
			return 3;
		default:
			return 0;
	}
	// STR_LOOKUP("one") // catch duplicate
}

static void test(char *p, int exp) {
	int h = test_hash(p);
	if (h != exp) {
		printf("%s:%i test failed: %u != %u (string '%s')\n", __FILE__, __LINE__, h, exp, p);
		abort();
	}
}

int main(void) {
	test("one", 1);
	test("two", 2);
	test("dashed-string", 3);
	test("doesn't exist", 0);
	return 0;
}

int get_local_log_level(unsigned int u) {
	return -1;
}