1 module tests.helper;
2 
3 import std.stdio;
4 import unit_threaded;
5 
6 import dinodave;
7 
8 @UnitTest
9 void put8_should_set_byte() {
10    ubyte[] a = [1, 2, 3, 4];
11    a.put8(50);
12    a.shouldEqual([50, 2, 3, 4]);
13    a.put8(51);
14    a.shouldEqual([51, 2, 3, 4]);
15 }
16 
17 @UnitTest
18 void put8at_should_set_byte_at_position() {
19    ubyte[] a = [1, 2, 3, 4];
20    a.put8At(0, 50);
21    a.shouldEqual([50, 2, 3, 4]);
22    a.put8At(1, 51);
23    a.shouldEqual([50, 51, 3, 4]);
24 
25    a.put8At(19, 52).shouldThrow!Exception;
26    a.put8At(-19, 52).shouldThrow!Exception;
27 
28       //ubyte* p = davePut8(a.ptr, 50);
29       //ubyte[] b = (p)[0..2];
30       //writeln(a);
31       //writeln(b);
32 }
33 @UnitTest
34 void daveput8at_should_set_byte_at_position() {
35    ubyte[] a = [1, 2, 3, 4];
36    davePut8At(a.ptr, 0, 50);
37    a.shouldEqual([50, 2, 3, 4]);
38    davePut8At(a.ptr, 1, 51);
39    a.shouldEqual([50, 51, 3, 4]);
40 
41    // Segmentation fault!!!!
42    //davePut8At(a.ptr, 19, 52).shouldNotThrow!Exception;
43    // davePut8At(a.ptr, -19, 52).shouldNotThrow!Exception;
44 }
45 
46 void testBcdToDec() {
47    (0x0).toBCD().shouldEqual(0);
48    (0x5).toBCD().shouldEqual(5);
49    (0xA).toBCD().shouldEqual(16);
50    (11).toBCD().shouldEqual(17);
51 } 
52 
53 void testStrerrr() {
54    strerror(0x8000).shouldEqual("function already occupied.");
55 
56    strerror(0x8001).shouldEqual("not allowed in current operating status.");
57    strerror(0x8101).shouldEqual("hardware fault.");
58    strerror(0x8103).shouldEqual("object access not allowed.");
59    strerror(0x8104).shouldEqual("context is not supported. Step7 says:Function not implemented or error in telgram.");
60    strerror(0x8105).shouldEqual("invalid address.");
61    strerror(0x8106).shouldEqual("data type not supported.");
62    strerror(0x8107).shouldEqual("data type not consistent.");
63    strerror(0x810A).shouldEqual("object does not exist.");
64    strerror(0x8500).shouldEqual("incorrect PDU size.");
65    strerror(0x8702).shouldEqual("address invalid.");
66    strerror(0xd201).shouldEqual("block name syntax error.");
67    strerror(0xd202).shouldEqual("syntax error function parameter.");
68    strerror(0xd203).shouldEqual("syntax error block type.");
69    strerror(0xd204).shouldEqual("no linked block in storage medium.");
70    strerror(0xd205).shouldEqual("object already exists.");
71    strerror(0xd206).shouldEqual("object already exists.");
72    strerror(0xd207).shouldEqual("block exists in EPROM.");
73    strerror(0xd209).shouldEqual("block does not exist/could not be found.");
74    strerror(0xd20e).shouldEqual("no block present.");
75    strerror(0xd210).shouldEqual("block number too big.");
76 }
77 
78 void testPut8() {
79    ubyte[] buf = [0, 2, 4];
80    buf[0].shouldEqual(0);
81    put8(buf, 10);
82    buf[0].shouldEqual(10);
83    buf.length.shouldEqual(3);
84    put8(buf, 0xFF);
85    writeln("e", buf[0]);
86 }