-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.c
More file actions
75 lines (66 loc) · 1.42 KB
/
test.c
File metadata and controls
75 lines (66 loc) · 1.42 KB
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
//
// test.c
// Simple DNS server
//
// Created by Eugeny Volobuev on 09.08.13.
// Copyright (c) 2013 Eugeny Volobuev. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "utils.h"
void test_read_uint8()
{
unsigned char buf = 128;
unsigned char val = 0;
read_uint8(&buf, &val);
assert(val == 128);
}
void test_read_uint16_lh()
{
short buf = 512;
unsigned short val = 0;
read_uint16(&buf, &val, false);
assert(val == 512);
}
void test_read_uint16_hl()
{
short buf = htons(512);
unsigned short val = 0;
read_uint16(&buf, &val, true);
assert(val == 512);
}
void test_write_uint8()
{
unsigned char buf;
unsigned char *start = &buf;
unsigned char val = 0x80;
write_uint8(&buf, &val);
assert(*start == 0x80);
}
void test_write_uint16_lh()
{
unsigned short buf;
unsigned short *start = &buf;
unsigned short val = 512;
write_uint16(&buf, &val, false);
assert(*start == 512);
}
void test_write_uint16_hl()
{
unsigned short buf;
unsigned short *start = &buf;
unsigned short val = htons(512);
write_uint16(&buf, &val, true);
assert(*start == 512);
}
int main(int argc, const char *argv[])
{
test_read_uint8();
test_read_uint16_lh();
test_read_uint16_hl();
test_write_uint8();
test_write_uint16_lh();
test_write_uint16_hl();
fprintf(stdout, "all tests sucessfully completed");
}