Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sbera87 committed Oct 7, 2024
1 parent 91c2115 commit fd8bfe0
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public CppBlockWriter(String header, int level){
openCodeBlock(header);
}


public CppBlockWriter(int level){
indentLevel = level;
blockStack = new Stack<>();
codeBlock = new String("");
}

//opens a new block
public CppBlockWriter openCodeBlock(String blockHead)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.amazonaws.util.awsclientsmithygenerator.generators;

import software.amazon.smithy.codegen.core.ImportContainer;
import software.amazon.smithy.codegen.core.Symbol;

import java.util.List;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.Map;

public final class CppImportContainer implements ImportContainer {

@Override
public void importSymbol(Symbol symbol, String alias) {
System.out.println("importSymbol called");
}

@Override
public String toString() {
System.out.println("toString called");
return "";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//package com.amazonaws.util.awsclientsmithygenerator.generators;
//
//import software.amazon.smithy.build.FileManifest;
//import software.amazon.smithy.codegen.core.SymbolProvider;
//import software.amazon.smithy.codegen.core.WriterDelegator;
//
///**
// * Manages writers for C# Files
// */
//public class CppSmokeTestsDelegator extends WriterDelegator<CppSmokeTestsWriter> {
//
// public CppSmokeTestsDelegator(FileManifest fileManifest, SymbolProvider symbolProvider) {
// super(fileManifest, symbolProvider, new CppSmokeTestsWriter.CppSmokeTestsWriterFactory());
// }
//}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
package com.amazonaws.util.awsclientsmithygenerator.generators;

import software.amazon.smithy.utils.SimpleCodeWriter;
import software.amazon.smithy.codegen.core.SymbolWriter;
import java.util.List;

import com.google.common.base.Optional;
public final class CppSmokeTestsWriter extends SimpleCodeWriter{
private String namespace;
//protected CppBlockWriter blockWriter;
public CppSmokeTestsWriter() {
public CppSmokeTestsWriter(String namespace) {
super();
this.namespace = namespace;
}

protected void useNamespaces()
{
write("$L|","using namespace Aws::Auth;\n" + //
write("${L|}","using namespace Aws::Auth;\n" + //
"using namespace Aws::Http;\n" + //
"using namespace Aws::Client;\n" + //
"using namespace Aws::$client;\n" + //
Expand All @@ -23,7 +26,7 @@ protected void useNamespaces()
//SimpleCodeWriter writer
protected void addHeaderBlock()
{
write("$L|",
write("${L|}",

"#include <aws/testing/AwsCppSdkGTestSuite.h>\n" + //
"#include <aws/testing/AwsTestHelpers.h>\n" + //
Expand All @@ -45,12 +48,12 @@ protected void addHeaderBlock()

protected void addClientHeader(TestcaseParams test)
{
write("#include <aws/$L.toLowerCase()/$LClient.h>", test.getClientName(), test.getClientName() );
write("#include <aws/$L/$LClient.h>", test.getClientName().toLowerCase(), test.getClientName() );
};

protected void addRequestHeader(TestcaseParams test)
{
write("#include <aws/$L.toLowerCase()/model/$LRequest.h>", test.getClientName(), test.getOperationName());
write("#include <aws/$L/model/$LRequest.h>", test.getClientName().toLowerCase(), test.getOperationName());
};

protected void defineTestFixture(TestcaseParams test)
Expand Down Expand Up @@ -82,7 +85,7 @@ protected void defineTestCase(TestcaseParams test)
test.getGetterCodeBlock().stream().forEach(getter -> {
write("$L", getter);
});
write("$L|", test.getFunctionBlock());
write("${L|}", test.getFunctionBlock());
write("auto outcome = clientSp->$L(input);",test.getOperationName());
if (test.isExpectSuccess())
{
Expand All @@ -105,11 +108,11 @@ public String GetSmokeTestsCode(List<TestcaseParams> tests)
{
addHeaderBlock();
addClientHeader(firstTest);
write("namespace $LSmokeTest{", firstTest.getClientName());


tests.stream().forEach(test -> {
addRequestHeader(test);
});
write("namespace $LSmokeTest{", firstTest.getClientName());
useNamespaces();

defineTestFixture(firstTest);
Expand All @@ -121,5 +124,16 @@ public String GetSmokeTestsCode(List<TestcaseParams> tests)
return toString();
}

/**
* The Factory class for creating CppWriters
*/
/*public static final class CppSmokeTestsWriterFactory implements SymbolWriter.Factory<CppSmokeTestsWriter> {
@Override
public CppSmokeTestsWriter apply(String filename, String namespace) {
return new CppSmokeTestsWriter(namespace);
}
}*/


}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Map;
import java.util.HashMap;
import java.io.*;

import java.util.List;
public class SmithyCodegenPlugin implements SmithyBuildPlugin {

@Override
Expand All @@ -26,10 +26,20 @@ public String getName() {
@Override
public void execute(PluginContext context){

System.out.println("Executing SmithyCodegenPlugin...");
System.out.println(String.format("Executing SmithyCodegenPlugin...", context.getFileManifest().getBaseDir().toString()));

SmokeTestsParser smoketestParser = new SmokeTestsParser(context.getModel());

Map<String, List<TestcaseParams> > smoketests = smoketestParser.extractServiceSmokeTests();

smoketests.entrySet().stream().forEach(entry -> {
List<TestcaseParams> tests = entry.getValue();
CppSmokeTestsWriter writer = new CppSmokeTestsWriter("");
String code = writer.GetSmokeTestsCode(tests);
System.out.println("Code:\n"+code);
}
);

SmokeTestsParser smoketestPrser = new SmokeTestsParser(context.getModel());
smoketestPrser.extractServiceSmokeTests();

/*CppBlockWriter blockWriter = new CppBlockWriter( String.format("void newFunction()"),0).
addCode("vector<int> test =").
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ public void GenerateSmokeTests() throws Exception {

List<TestcaseParams> testcaseParams = extractTests();

//genrate test code
CppSmokeTestsWriter smithySmokeTests = new CppSmokeTestsWriter();
System.out.println(smithySmokeTests.GetSmokeTestsCode(testcaseParams));

GenerateSmokeTestsourceFile(testcaseParams, String.format(SMOKE_TESTS_CPP_FORMAT, serviceName), serviceName);
generateTestCmakeFile(CMAKE_LISTS_TXT, serviceName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public SmokeTestsParser(Model model)
{
this.model = model;
codegenAdapter = new SmithyCodegenAdapter(model);

}


//for given smoke test trait in an operation for a service, parse smoke tests
private List<TestcaseParams> parseSmokeTests(
SmokeTestsTrait smokeTestsTrait,
OperationShape operationShape,
Expand All @@ -56,7 +55,12 @@ private List<TestcaseParams> parseSmokeTests(
//operation name
TestcaseParams test = new TestcaseParams();
String clientName = serviceShape.getId().getName();
test.setClientName(clientName.substring(0, clientName.indexOf('_')));
System.out.println("clientName="+clientName);

int underscoreIndex = clientName.indexOf('_');
// Check if underscore exists, otherwise return the whole string
clientName = underscoreIndex != -1 ? clientName.substring(0, underscoreIndex) : clientName;
test.setClientName(clientName);
test.setOperationName(operationShape.getId().getName());

String inputShapeName = operationShape.getInput()
Expand Down Expand Up @@ -86,6 +90,9 @@ private List<TestcaseParams> parseSmokeTests(
Map<String, Shape> fieldShapeMap = codegenAdapter.getMemberShapes(topLevelShape.get());

//declare top level variable
CppBlockWriter blockWriter = new CppBlockWriter(0)
.addCode(String.format("%sRequest %s;\n", test.getOperationName(), "input"));

sb.append(String.format("%sRequest %s;\n", test.getOperationName(), "input"));
for (Map.Entry<String, Node> paramEntry : testcase.getParams().get().getStringMap().entrySet()) {
String key = paramEntry.getKey();
Expand All @@ -99,6 +106,17 @@ private List<TestcaseParams> parseSmokeTests(
}

try {
blockWriter.addCode(String.format("input.Set%s(%s);\n", key,

codegenAdapter.GenerateCppSetters(
test.getOperationName().toLowerCase() + "_elem",
value,
fieldShape, //useful for C++ return type object
1, //useful for depth
0, //useful for array elements at same depth
functionMap)
));

sb.append(String.format("input.Set%s(%s);\n", key,

codegenAdapter.GenerateCppSetters(
Expand All @@ -113,8 +131,9 @@ private List<TestcaseParams> parseSmokeTests(
throw new RuntimeException(e);
}
}

test.setFunctionBlock(sb.toString());
//test.setFunctionBlock(blockWriter.getCode());

List<String> lines = new ArrayList<>();

Expand Down Expand Up @@ -240,16 +259,22 @@ public Map<String, List<TestcaseParams> > extractServiceSmokeTests()

ServiceShape serviceShape = serviceShapeMap.get(serviceName);

System.out.println("OperationShape: " + operationShape.getName());
System.out.println("OperationShape: " + operationShape.getId().getName());
System.out.println("serviceName: " + serviceName);


//parseSmokeTests(
// SmokeTestsTrait smokeTestsTrait,
// OperationShape operationShape,
// ServiceShape serviceShape )


List<TestcaseParams> tests = parseSmokeTests(
smokeTestsTrait,
operationShape,
serviceShape );
//add to tests for the same service
if(serviceSmokeTestsMap.containsKey(serviceName))
{
serviceSmokeTestsMap.get(serviceName).addAll(tests);
}
else
{
serviceSmokeTestsMap.put(serviceName, tests);
}

});

Expand Down

0 comments on commit fd8bfe0

Please sign in to comment.