Mercurial > hg > orthanc-stone
annotate Resources/CodeGeneration/stonegentool_test.py @ 482:f58fe38c8c04 bgo-commands-codegen
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
author | bgo-osimis |
---|---|
date | Thu, 14 Feb 2019 20:58:42 +0100 |
parents | 38997ceb9bc6 |
children | 772516adcbf6 |
rev | line source |
---|---|
474 | 1 from stonegentool import \ |
2 EatToken,SplitListOfTypes,ParseTemplateType,LoadSchema,CheckSchemaSchema,ProcessSchema | |
471 | 3 import unittest |
473 | 4 import os |
471 | 5 |
6 class TestStonegentool(unittest.TestCase): | |
7 def test_EatToken_empty(self): | |
8 c = r"" | |
9 a,b = EatToken(c) | |
10 self.assertEqual(a,r"") | |
11 self.assertEqual(b,r"") | |
12 | |
13 def test_EatToken_simpleNonTemplate(self): | |
14 c = r"int32" | |
15 a,b = EatToken(c) | |
16 self.assertEqual(a,r"int32") | |
17 self.assertEqual(b,r"") | |
18 | |
19 def test_EatToken_simpleTemplate(self): | |
20 c = r"vector<string>" | |
21 a,b = EatToken(c) | |
22 self.assertEqual(a,r"vector<string>") | |
23 self.assertEqual(b,r"") | |
24 | |
25 def test_EatToken_complexTemplate(self): | |
26 c = r"vector<map<int64,string>>,vector<map<int32,string>>" | |
27 a,b = EatToken(c) | |
28 self.assertEqual(a,r"vector<map<int64,string>>") | |
29 self.assertEqual(b,r"vector<map<int32,string>>") | |
30 | |
472 | 31 def test_EatToken_complexTemplates(self): |
471 | 32 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>" |
33 a,b = EatToken(c) | |
34 self.assertEqual(a,r"vector<map<vector<string>,map<int32,string>>>") | |
35 self.assertEqual(b,r"map<int32,string>,map<map<int32,string>,string>") | |
36 a,b = EatToken(b) | |
37 self.assertEqual(a,r"map<int32,string>") | |
38 self.assertEqual(b,r"map<map<int32,string>,string>") | |
39 | |
473 | 40 def test_SplitListOfTypes(self): |
41 c = r"vector<map<vector<string>,map<int32,string>>>,map<int32,string>,map<map<int32,string>,string>" | |
42 lot = SplitListOfTypes(c) | |
43 self.assertEqual(3,len(lot)) | |
44 self.assertEqual("vector<map<vector<string>,map<int32,string>>>",lot[0]) | |
45 self.assertEqual("map<int32,string>",lot[1]) | |
46 self.assertEqual("map<map<int32,string>,string>",lot[2]) | |
47 | |
48 def test_SplitListOfTypes_bogus(self): | |
49 c = r"vector<map<vector<string>,map<int32,string>>,map<int32,string>,map<map<int32,string>,string" | |
50 self.assertRaises(Exception,SplitListOfTypes,c) # the argument c must be passed to assertRaises, not as a normal call of SplitListOfTypes | |
51 | |
52 def test_ParseTemplateType_true(self): | |
53 c = "map<vector<map<int,vector<string>>>,map<vector<int>,vector<string>>>" | |
54 (ok,a,b) = ParseTemplateType(c) | |
55 self.assertEqual(ok,True) | |
56 self.assertEqual(a,"map") | |
57 self.assertEqual(b,["vector<map<int,vector<string>>>","map<vector<int>,vector<string>>"]) | |
58 | |
59 (ok2,a2,b2) = ParseTemplateType(b[0]) | |
60 self.assertEqual(ok2,True) | |
61 self.assertEqual(a2,"vector") | |
62 self.assertEqual(b2,["map<int,vector<string>>"]) | |
63 | |
64 (ok3,a3,b3) = ParseTemplateType(b[1]) | |
65 self.assertEqual(ok3,True) | |
66 self.assertEqual(a3,"map") | |
67 self.assertEqual(b3,["vector<int>","vector<string>"]) | |
68 | |
69 (ok4,a4,b4) = ParseTemplateType(b2[0]) | |
70 self.assertEqual(ok4,True) | |
71 self.assertEqual(a4,"map") | |
72 self.assertEqual(b4,["int","vector<string>"]) | |
73 | |
74 def test_ParseSchema(self): | |
75 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') | |
76 obj = LoadSchema(fn) | |
77 # we're happy if it does not crash | |
78 CheckSchemaSchema(obj) | |
79 | |
80 def test_ParseSchema_bogus_json(self): | |
81 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_json.jsonc') | |
82 self.assertRaises(Exception,LoadSchema,fn) | |
83 | |
84 def test_ParseSchema_bogus_schema(self): | |
85 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1_bogus_schema.jsonc') | |
86 obj = LoadSchema(fn) | |
87 self.assertRaises(Exception,CheckSchemaSchema,obj) | |
88 | |
474 | 89 def test_GenOrderQueue(self): |
90 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') | |
91 obj = LoadSchema(fn) | |
482
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
92 genOrderQueue, outputStreams = ProcessSchema(obj) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
93 self.assertEqual(3,len(genOrderQueue)) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
94 self.assertEqual("A",genOrderQueue[0]) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
95 self.assertEqual("B",genOrderQueue[0]) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
96 self.assertEqual("C",genOrderQueue[0]) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
97 #print(f"genOrderQueue = {genOrderQueue}") |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
98 #print("") |
473 | 99 |
474 | 100 def test_GenerateTypeScriptEnumeration(self): |
482
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
101 fn = os.path.join(os.path.dirname(__file__), 'test', 'test1.jsonc') |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
102 obj = LoadSchema(fn) |
f58fe38c8c04
Ongoing work on codegen: ts and cpp enum and struct writing seem to be OK. No file write yet
bgo-osimis
parents:
474
diff
changeset
|
103 (rootName,outputStreams) = ProcessSchema(obj) |
474 | 104 pass |
473 | 105 |
474 | 106 def test_GenerateCppEnumeration(self): |
107 pass | |
108 | |
109 def test_GenerateTypeScriptClasses(self): | |
110 pass | |
111 | |
112 def test_GenerateCppClasses(self): | |
113 pass | |
114 | |
115 def test_GenerateTypeScriptHandlerInterface(self): | |
116 pass | |
117 | |
118 def test_GenerateCppHandlerInterface(self): | |
119 pass | |
120 | |
121 def test_GenerateTypeScriptDispatcher(self): | |
122 pass | |
123 | |
124 def test_GenerateCppDispatcher(self): | |
125 pass | |
473 | 126 |
472 | 127 # def test(self): |
471 | 128 # s = 'hello world' |
129 # self.assertEqual(s.split(), ['hello', 'world']) | |
130 # # check that s.split fails when the separator is not a string | |
131 # with self.assertRaises(TypeError): | |
132 # s.split(2) | |
133 | |
134 if __name__ == '__main__': | |
474 | 135 print("") |
136 unittest.main() |