summaryrefslogtreecommitdiff
path: root/examples/ExampleTest.cc
blob: 8947c9ba71a4d14952e5b720cbe1dec69aa65cde (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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <uunit.h>

#include "getbaud.h"

class ExampleTest
	: public uUnit
{
public:
	ExampleTest()
	{
		uTEST(ExampleTest::boundaryTests);
		uTEST(ExampleTest::exceptionTests);
	}

	void boundaryTests()
	{
		uASSERT_EQUAL(B0, getBaud(0));
		uASSERT_EQUAL(B0, getBaud(1));
		uASSERT_EQUAL(B0, getBaud(49));

		uASSERT_EQUAL(B50, getBaud(50));
		uASSERT_EQUAL(B50, getBaud(51));
		uASSERT_EQUAL(B50, getBaud(74));

		uASSERT_EQUAL(B75, getBaud(75));
		uASSERT_EQUAL(B75, getBaud(76));
		uASSERT_EQUAL(B75, getBaud(109));

		uASSERT_EQUAL(B110, getBaud(110));
		uASSERT_EQUAL(B110, getBaud(111));
		uASSERT_EQUAL(B110, getBaud(133));

		uASSERT_EQUAL(B134, getBaud(134));
		uASSERT_EQUAL(B134, getBaud(135));
		uASSERT_EQUAL(B134, getBaud(149));

		uASSERT_EQUAL(B150, getBaud(150));
		uASSERT_EQUAL(B150, getBaud(151));
		uASSERT_EQUAL(B150, getBaud(199));

		uASSERT_EQUAL(B200, getBaud(200));
		uASSERT_EQUAL(B200, getBaud(201));
		uASSERT_EQUAL(B200, getBaud(299));

		uASSERT_EQUAL(B300, getBaud(300));
		uASSERT_EQUAL(B300, getBaud(301));
		uASSERT_EQUAL(B300, getBaud(599));

		uASSERT_EQUAL(B600, getBaud(600));
		uASSERT_EQUAL(B600, getBaud(601));
		uASSERT_EQUAL(B600, getBaud(1199));

		uASSERT_EQUAL(B1200, getBaud(1200));
		uASSERT_EQUAL(B1200, getBaud(1201));
		uASSERT_EQUAL(B1200, getBaud(1799));

		uASSERT_EQUAL(B1800, getBaud(1800));
		uASSERT_EQUAL(B1800, getBaud(1801));
		uASSERT_EQUAL(B1800, getBaud(2399));

		uASSERT_EQUAL(B2400, getBaud(2400));
		uASSERT_EQUAL(B2400, getBaud(2401));
		uASSERT_EQUAL(B2400, getBaud(4799));

		uASSERT_EQUAL(B4800, getBaud(4800));
		uASSERT_EQUAL(B4800, getBaud(4801));
		uASSERT_EQUAL(B4800, getBaud(9599));

		uASSERT_EQUAL(B9600, getBaud(9600));
		uASSERT_EQUAL(B9600, getBaud(9601));
		uASSERT_EQUAL(B9600, getBaud(19199));

		uASSERT_EQUAL(B19200, getBaud(19200));
		uASSERT_EQUAL(B19200, getBaud(19201));
		uASSERT_EQUAL(B19200, getBaud(38399));

		uASSERT_EQUAL(B38400, getBaud(38400));
		uASSERT_EQUAL(B38400, getBaud(38401));
		uASSERT_EQUAL(B38400, getBaud(57599));

		uASSERT_EQUAL(B57600, getBaud(57600));
		uASSERT_EQUAL(B57600, getBaud(57601));
		uASSERT_EQUAL(B57600, getBaud(115199));

		uASSERT_EQUAL(B115200, getBaud(115200));
		uASSERT_EQUAL(B115200, getBaud(115201));
		uASSERT_EQUAL(B115200, getBaud(230399));

		uASSERT_EQUAL(B230400, getBaud(230400));
		uASSERT_EQUAL(B230400, getBaud(230401));
	}

	void exceptionTests()
	{
		uASSERT_THROWS(bad_speed, getBaud(-1));
	}
};

// Registers the fixture into the 'registry'
static ExampleTest test;