Search in sources :

Example 1 with TestFileUtilsImpl

use of com.spectralogic.ds3autogen.utils.TestFileUtilsImpl in project ds3_autogen by SpectraLogic.

the class CCodeGenerator_Test method testGenerateSimpleTypedefStruct.

@Test
public void testGenerateSimpleTypedefStruct() throws IOException, ParseException, TemplateModelException {
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Map<String, Object> testMap = new HashMap<>();
    final Struct structEntry = new Struct("ds3_bucket_response", ImmutableList.of(new StructMember(new FreeableType("ds3_str", false), "creation_date"), new StructMember(new FreeableType("ds3_str", false), "data_policy_id"), new StructMember(new FreeableType("ds3_str", false), "id"), new StructMember(new PrimitiveType("uint64_t", false), "last_preferred_chunk_size_in_bytes"), new StructMember(new PrimitiveType("uint64_t", false), "logical_used_capacity"), new StructMember(new FreeableType("ds3_str", false), "name"), new StructMember(new FreeableType("ds3_str", false), "user_id")));
    testMap.put("structEntry", structEntry);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(testMap, "header-templates/TypedefStruct.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    final String expectedOutput = "typedef struct {" + "\n" + "    ds3_str* creation_date;" + "\n" + "    ds3_str* data_policy_id;" + "\n" + "    ds3_str* id;" + "\n" + "    uint64_t last_preferred_chunk_size_in_bytes;" + "\n" + "    uint64_t logical_used_capacity;" + "\n" + "    ds3_str* name;" + "\n" + "    ds3_str* user_id;" + "\n" + "}ds3_bucket_response;" + "\n";
    assertThat(expectedOutput, is(output));
}
Also used : TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) HashMap(java.util.HashMap) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with TestFileUtilsImpl

use of com.spectralogic.ds3autogen.utils.TestFileUtilsImpl in project ds3_autogen by SpectraLogic.

the class CCodeGenerator_Test method testSimpleTypdefStructResponseParser.

@Test
public void testSimpleTypdefStructResponseParser() throws IOException, ParseException, TemplateModelException {
    final String inputSpecFile = "/input/SimpleTypedefStruct.xml";
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
    final ImmutableList<Request> allRequests = CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl());
    final ImmutableList<Enum> allEnums = CCodeGenerator.getAllEnums(spec);
    final ImmutableSet<String> enumNames = EnumHelper.getEnumNamesSet(allEnums);
    final ImmutableSet<String> arrayMemberTypes = CCodeGenerator.getArrayMemberTypes(spec, enumNames);
    final ImmutableSet<String> responseTypes = RequestHelper.getResponseTypes(allRequests);
    final ImmutableList<Struct> allStructs = CCodeGenerator.getAllStructs(spec, enumNames, responseTypes, arrayMemberTypes, ImmutableSet.of(), ImmutableSet.of());
    final ImmutableList<Struct> allOrderedStructs = StructHelper.getStructsOrderedList(allStructs, enumNames);
    final Source source = SourceConverter.toSource(allEnums, allOrderedStructs, allRequests);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(source, "source-templates/ds3_c.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    assertTrue(output.contains("static ds3_error* _parse_top_level_ds3_bucket_response(const ds3_client* client, const ds3_request* request, ds3_bucket_response** _response, GByteArray* xml_blob) {"));
    assertTrue(output.contains("    xmlNodePtr child_node;"));
    assertTrue(output.contains("    ds3_error* error;"));
    assertTrue(output.contains("    ds3_bucket_response* response;"));
    assertTrue(output.contains("    error = _get_request_xml_nodes(xml_blob, &doc, &root, \"Data\");"));
    assertTrue(output.contains("    if (error != NULL) {"));
    assertTrue(output.contains("        return error;"));
    assertTrue(output.contains("    }"));
    assertTrue(output.contains("    response = g_new0(ds3_bucket_response, 1)"));
    assertTrue(output.contains("    for (child_node = root->xmlChildrenNode; child_node != NULL; child_node = child_node->next) {"));
    assertTrue(output.contains("        if (element_equal(child_node, \"CreationDate\")) {"));
    assertTrue(output.contains("            response->creation_date = xml_get_string(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"DataPolicyId\")) {"));
    assertTrue(output.contains("            response->data_policy_id = xml_get_string(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"Id\")) {"));
    assertTrue(output.contains("            response->id = xml_get_string(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"LastPreferredChunkSizeInBytes\")) {"));
    assertTrue(output.contains("            response->last_preferred_chunk_size_in_bytes = xml_get_uint64(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"LogicalUsedCapacity\")) {"));
    assertTrue(output.contains("            response->logical_used_capacity = xml_get_uint64(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"Name\")) {"));
    assertTrue(output.contains("            response->name = xml_get_string(doc, child_node);"));
    assertTrue(output.contains("        } else if (element_equal(child_node, \"UserId\")) {"));
    assertTrue(output.contains("            response->user_id = xml_get_string(doc, child_node);"));
    assertTrue(output.contains("        } else {"));
    assertTrue(output.contains("            ds3_log_message(client->log, DS3_ERROR, \"Unknown node[%s] of ds3_bucket_response [%s]\\n\", child_node->name, root->name);"));
    assertTrue(output.contains("        }"));
    assertTrue(output.contains("    }"));
    assertTrue(output.contains("    xmlFreeDoc(doc);"));
    assertTrue(output.contains("    if (error == NULL) {"));
    assertTrue(output.contains("        *_response = response;"));
    assertTrue(output.contains("    } else {"));
    assertTrue(output.contains("        ds3_bucket_response_free(response);"));
    assertTrue(output.contains("    }"));
    assertTrue(output.contains("    return error;"));
    assertTrue(output.contains("}"));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Test(org.junit.Test)

Example 3 with TestFileUtilsImpl

use of com.spectralogic.ds3autogen.utils.TestFileUtilsImpl in project ds3_autogen by SpectraLogic.

the class CCodeGenerator_Test method testComplexResponseStructParserOrdering.

@Test
public void testComplexResponseStructParserOrdering() throws IOException, ParseException, TemplateModelException {
    final String inputSpecFile = "/input/ComplexTypedefStruct.xml";
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
    final ImmutableList<Request> allRequests = CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl());
    final ImmutableList<Enum> allEnums = CCodeGenerator.getAllEnums(spec);
    final ImmutableSet<String> enumNames = EnumHelper.getEnumNamesSet(allEnums);
    final ImmutableSet<String> arrayMemberTypes = CCodeGenerator.getArrayMemberTypes(spec, enumNames);
    final ImmutableSet<String> responseTypes = RequestHelper.getResponseTypes(allRequests);
    final ImmutableList<Struct> allStructs = CCodeGenerator.getAllStructs(spec, enumNames, responseTypes, arrayMemberTypes, ImmutableSet.of("ds3_bucket_details_response", "ds3_list_all_my_buckets_result_response"), ImmutableSet.of());
    final ImmutableList<Struct> allOrderedStructs = StructHelper.getStructsOrderedList(allStructs, enumNames);
    final Source source = SourceConverter.toSource(allEnums, allOrderedStructs, allRequests);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(source, "source-templates/ds3_c.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    assertTrue(output.indexOf("_parse_ds3_bucket_details_response_array") > output.indexOf("_parse_ds3_bucket_response"));
    assertTrue(output.indexOf("_parse_ds3_list_all_my_buckets_result_response") > output.indexOf("_parse_ds3_bucket_response_array"));
}
Also used : Enum(com.spectralogic.ds3autogen.c.models.Enum) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Test(org.junit.Test)

Example 4 with TestFileUtilsImpl

use of com.spectralogic.ds3autogen.utils.TestFileUtilsImpl in project ds3_autogen by SpectraLogic.

the class CCodeGenerator_Test method testRequestDocumentationCommentBlockWithEmptyDocSpecNoOptionalParams.

@Test
public void testRequestDocumentationCommentBlockWithEmptyDocSpecNoOptionalParams() throws IOException, TemplateModelException {
    final Request testRequest = RequestConverter.toRequest(Ds3ModelFixtures.getSystemInformationRequest(), new Ds3DocSpecEmptyImpl());
    final Map<String, Object> testMap = new HashMap<>();
    testMap.put("requestEntry", testRequest);
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    codeGenerator.processTemplate(testMap, "header-templates/RequestCommentDocumentation.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    assertEquals("", output);
}
Also used : TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) HashMap(java.util.HashMap) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 5 with TestFileUtilsImpl

use of com.spectralogic.ds3autogen.utils.TestFileUtilsImpl in project ds3_autogen by SpectraLogic.

the class CCodeGeneratorSpectraS3Requests_Test method testGenerateSpectraS3DeleteBucketRequest.

@Test
public void testGenerateSpectraS3DeleteBucketRequest() throws IOException, ParseException, TemplateModelException {
    final String inputSpecFile = "/input/SpectraS3DeleteBucketRequest.xml";
    final TestFileUtilsImpl fileUtils = new TestFileUtilsImpl();
    final Ds3SpecParser parser = new Ds3SpecParserImpl();
    final Ds3ApiSpec spec = parser.getSpec(CCodeGenerator_Test.class.getResourceAsStream(inputSpecFile));
    final Source source = SourceConverter.toSource(CCodeGenerator.getAllEnums(spec), CCodeGenerator.getAllStructs(spec, ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of(), ImmutableSet.of()), CCodeGenerator.getAllRequests(spec, new Ds3DocSpecEmptyImpl()));
    final CCodeGenerator codeGenerator = new CCodeGenerator();
    codeGenerator.processTemplate(source, "source-templates/ds3_c.ftl", fileUtils.getOutputStream());
    final ByteArrayOutputStream bstream = (ByteArrayOutputStream) fileUtils.getOutputStream();
    final String output = new String(bstream.toByteArray());
    assertTrue(output.contains("ds3_error* ds3_delete_bucket_spectra_s3_request(const ds3_client* client, const ds3_request* request) {"));
    assertTrue(output.contains("    int num_slashes = num_chars_in_ds3_str(request->path, '/');"));
    assertTrue(output.contains("    if (num_slashes < 2 || ((num_slashes == 2) && ('/' == request->path->value[request->path->size-1]))) {"));
    assertTrue(output.contains("        return ds3_create_error(DS3_ERROR_MISSING_ARGS, \"The resource id parameter is required.\");"));
    assertTrue(output.contains("    } else if (g_ascii_strncasecmp(request->path->value, \"//\", 2) == 0) {"));
    assertTrue(output.contains("        return ds3_create_error(DS3_ERROR_MISSING_ARGS, \"The resource type parameter is required.\");"));
    assertTrue(output.contains("    }"));
    assertTrue(output.contains("    return _internal_request_dispatcher(client, request, NULL, NULL, NULL, NULL, NULL);"));
    assertTrue(output.contains("}"));
}
Also used : TestFileUtilsImpl(com.spectralogic.ds3autogen.utils.TestFileUtilsImpl) Ds3SpecParser(com.spectralogic.ds3autogen.api.Ds3SpecParser) Ds3DocSpecEmptyImpl(com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl) Ds3SpecParserImpl(com.spectralogic.ds3autogen.Ds3SpecParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Source(com.spectralogic.ds3autogen.c.models.Source) Ds3ApiSpec(com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec) Test(org.junit.Test)

Aggregations

TestFileUtilsImpl (com.spectralogic.ds3autogen.utils.TestFileUtilsImpl)43 Test (org.junit.Test)43 ByteArrayOutputStream (java.io.ByteArrayOutputStream)40 Ds3DocSpecEmptyImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecEmptyImpl)35 Ds3SpecParserImpl (com.spectralogic.ds3autogen.Ds3SpecParserImpl)23 Ds3SpecParser (com.spectralogic.ds3autogen.api.Ds3SpecParser)23 Ds3ApiSpec (com.spectralogic.ds3autogen.api.models.apispec.Ds3ApiSpec)23 HashMap (java.util.HashMap)21 Enum (com.spectralogic.ds3autogen.c.models.Enum)15 Request (com.spectralogic.ds3autogen.c.models.Request)14 Source (com.spectralogic.ds3autogen.c.models.Source)9 Ds3Request (com.spectralogic.ds3autogen.api.models.apispec.Ds3Request)3 NameMapper (com.spectralogic.ds3autogen.NameMapper)2 Ds3DocSpecParser (com.spectralogic.ds3autogen.api.Ds3DocSpecParser)2 Ds3Param (com.spectralogic.ds3autogen.api.models.apispec.Ds3Param)2 Ds3Type (com.spectralogic.ds3autogen.api.models.apispec.Ds3Type)2 Ds3DocSpec (com.spectralogic.ds3autogen.api.models.docspec.Ds3DocSpec)2 Ds3DocSpecParserImpl (com.spectralogic.ds3autogen.docspec.Ds3DocSpecParserImpl)2 CodeGenerator (com.spectralogic.ds3autogen.api.CodeGenerator)1 FileUtils (com.spectralogic.ds3autogen.api.FileUtils)1