6
6
package com .amazonaws .util .awsclientgenerator .generators .cpp ;
7
7
8
8
import com .amazonaws .util .awsclientgenerator .domainmodels .SdkFileEntry ;
9
- import com .amazonaws .util .awsclientgenerator .domainmodels .c2j .C2jServiceModel ;
10
- import com .amazonaws .util .awsclientgenerator .domainmodels .c2j_protocol_test .C2jTestSuite ;
9
+
11
10
import com .amazonaws .util .awsclientgenerator .domainmodels .codegeneration .ServiceModel ;
12
11
12
+ import com .amazonaws .util .awsclientgenerator .domainmodels .codegeneration .cpp .CppViewHelper ;
13
+ import com .amazonaws .util .awsclientgenerator .domainmodels .protocol_test .ProtocolTestModel ;
14
+ import com .amazonaws .util .awsclientgenerator .domainmodels .protocol_test .ProtocolTestSuite ;
13
15
import com .amazonaws .util .awsclientgenerator .generators .ClientGenerator ;
14
16
import com .amazonaws .util .awsclientgenerator .generators .exceptions .SourceGenerationFailedException ;
15
17
import org .apache .velocity .Template ;
22
24
import java .io .IOException ;
23
25
import java .io .StringWriter ;
24
26
import java .nio .charset .StandardCharsets ;
25
- import java .util .ArrayList ;
26
- import java .util .List ;
27
+ import java .util .* ;
28
+ import java .util .stream . Collectors ;
27
29
28
30
public class CppProtocolTestGenerator implements ClientGenerator {
29
31
30
32
private static String CMAKE_LISTS_TEMPLATE = "/com/amazonaws/util/awsclientgenerator/velocity/cpp/protocoltests/ProtocolTestsCMakeLists.vm" ;
31
- private static String TEST_DRIVER_TEMPLATE = "/com/amazonaws/util/awsclientgenerator/velocity/cpp/protocoltests/ProtocolTestsSource.vm" ;
33
+ private static String RUN_TESTS_TEMPLATE = "/com/amazonaws/util/awsclientgenerator/velocity/cpp/protocoltests/ProtocolTestsRunTestsSrc.vm" ;
34
+ private static String TEST_SUITE_TEMPLATE = "/com/amazonaws/util/awsclientgenerator/velocity/cpp/protocoltests/ProtocolTestsTestSuiteSrc.vm" ;
32
35
33
36
protected final VelocityEngine velocityEngine ;
34
37
private final ServiceModel serviceModel ;
35
- private final C2jTestSuite testModel ; // TODO: use an intermediate codegen model instead of raw C2J
38
+ private final ProtocolTestModel testModel ; // TODO: use an intermediate codegen model instead of raw C2J
36
39
private final String projectName ;
37
40
38
- public CppProtocolTestGenerator (ServiceModel serviceModel , C2jTestSuite testSuiteModel ) throws Exception {
41
+ public CppProtocolTestGenerator (ServiceModel serviceModel , ProtocolTestModel testSuiteModel ) throws Exception {
39
42
this .serviceModel = serviceModel ;
40
43
this .testModel = testSuiteModel ;
41
44
String prefix = testSuiteModel .getType ().toString ().toLowerCase ();
@@ -52,10 +55,32 @@ public CppProtocolTestGenerator(ServiceModel serviceModel, C2jTestSuite testSuit
52
55
velocityEngine .init ();
53
56
}
54
57
58
+ protected SdkFileEntry generateTestSuiteSourceFile (ProtocolTestSuite testSuite ) throws IOException {
59
+ VelocityContext context = createContext ();
60
+ context .put ("testSuite" , testSuite );
61
+ Template template = velocityEngine .getTemplate (TEST_SUITE_TEMPLATE , StandardCharsets .UTF_8 .name ());
62
+ String fileName = String .format ("tests/%sTest.cpp" , testSuite .getName ());
63
+
64
+ return makeFile (template , context , fileName , true );
65
+ }
66
+
67
+ protected List <SdkFileEntry > generateTestSuiteSourceFiles () throws IOException {
68
+ return testModel .getTestSuites ().stream ()
69
+ .map (entry -> {
70
+ try {
71
+ return generateTestSuiteSourceFile (entry );
72
+ } catch (IOException e ) {
73
+ throw new RuntimeException (e );
74
+ }
75
+ })
76
+ .collect (Collectors .toList ());
77
+ }
78
+
55
79
public SdkFileEntry [] generateSourceFiles (ServiceModel dummy ) throws Exception {
56
80
List <SdkFileEntry > fileList = new ArrayList <>();
57
81
fileList .add (generateCmakeFile ());
58
82
fileList .add (generateTestDriver ());
83
+ fileList .addAll (generateTestSuiteSourceFiles ());
59
84
60
85
SdkFileEntry [] retArray = new SdkFileEntry [fileList .size ()];
61
86
return fileList .toArray (retArray );
@@ -69,7 +94,7 @@ private SdkFileEntry generateCmakeFile() throws Exception {
69
94
70
95
protected SdkFileEntry generateTestDriver () throws Exception {
71
96
VelocityContext context = createContext ();
72
- Template template = velocityEngine .getTemplate (TEST_DRIVER_TEMPLATE , StandardCharsets .UTF_8 .name ());
97
+ Template template = velocityEngine .getTemplate (RUN_TESTS_TEMPLATE , StandardCharsets .UTF_8 .name ());
73
98
return makeFile (template , context , "RunTests.cpp" , true );
74
99
}
75
100
@@ -81,6 +106,8 @@ protected final VelocityContext createContext() {
81
106
context .put ("testModel" , testModel );
82
107
context .put ("input.encoding" , StandardCharsets .UTF_8 .name ());
83
108
context .put ("output.encoding" , StandardCharsets .UTF_8 .name ());
109
+
110
+ context .put ("CppViewHelper" , CppViewHelper .class );
84
111
return context ;
85
112
}
86
113
0 commit comments