Skip to content

Commit

Permalink
Merge branch 'xmidt-org:master' into multipart_test_cases
Browse files Browse the repository at this point in the history
  • Loading branch information
suvi-123 committed Nov 9, 2023
2 parents fbde8ab + ce9f409 commit 47af39c
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 65 deletions.
7 changes: 0 additions & 7 deletions src/webcfg_multipart.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,9 @@ char * get_global_interface(void)
/*----------------------------------------------------------------------------*/
/* Function Prototypes */
/*----------------------------------------------------------------------------*/
size_t writer_callback_fn(void *buffer, size_t size, size_t nmemb, void *datain);
size_t headr_callback(char *buffer, size_t size, size_t nitems, void* data);
void stripspaces(char *str, char **final_str);
void line_parser(char *ptr, int no_of_bytes, char **name_space, uint32_t *etag, char **data, size_t *data_size);
void subdoc_parser(char *ptr, int no_of_bytes);
void addToDBList(webconfig_db_data_t *webcfgdb);
char* generate_trans_uuid();
WEBCFG_STATUS processMsgpackSubdoc(char *transaction_id);
void loadInitURLFromFile(char **url);
void get_webCfg_interface(char **interface);

#ifdef FEATURE_SUPPORT_AKER
WEBCFG_STATUS checkAkerDoc();
Expand Down
133 changes: 133 additions & 0 deletions tests/test_blob.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <base64.h>
#include <msgpack.h>
#include <CUnit/Basic.h>
#include "../src/webcfg_blob.h"
#include "../src/webcfg_log.h"
#define UNUSED(x) (void )(x)
bool rbus_enable = true;
bool isRbusEnabled()
{

return rbus_enable;
}
bool isRbusListener(char *subDoc)
{
UNUSED(subDoc);
return true;
}
char * base64blobencoder(char * blob_data, size_t blob_size )
{
char* b64buffer = NULL;
size_t encodeSize = -1;
WebcfgDebug("Data is %s\n", blob_data);
WebcfgDebug("-----------Start of Base64 Encode ------------\n");
encodeSize = b64_get_encoded_buffer_size(blob_size);
WebcfgDebug("encodeSize is %zu\n", encodeSize);
b64buffer = malloc(encodeSize + 1);
if(b64buffer != NULL)
{
memset( b64buffer, 0, sizeof( encodeSize )+1 );

b64_encode((uint8_t *)blob_data, blob_size, (uint8_t *)b64buffer);
b64buffer[encodeSize] = '\0' ;
}
return b64buffer;
}
void test_writeToFileData()
{
char* db_file_path = "test.txt";
char* data = NULL;
size_t size = 0;
// Failed to create/open file in root
CU_ASSERT_EQUAL(writeToFileData("/test.txt", data, size), 0);
// NULL data pointer
CU_ASSERT_EQUAL(writeToFileData(db_file_path, data, size), 0);
// with data
CU_ASSERT_EQUAL(writeToFileData(db_file_path, "data", 5), 1);
//Removing created test.txt file
if (remove(db_file_path) != 0) {
CU_FAIL("Failed to remove file");
}
}

void test_webcfg_appendeddoc()
{
char *appended_doc = NULL;
int embPackSize = 0;
uint16_t trans_id = 0;
appended_doc = webcfg_appendeddoc("subdoc1", 1234, "test", 5, &trans_id, &embPackSize);
CU_ASSERT_NOT_EQUAL(embPackSize,0);
CU_ASSERT_FATAL( 0 != appended_doc);
rbus_enable = false;
appended_doc = webcfg_appendeddoc("subdoc2", 1234, "test", 5, &trans_id, &embPackSize);
CU_ASSERT_NOT_EQUAL(embPackSize,0);
CU_ASSERT_FATAL( 0 != appended_doc);
rbus_enable = true;
}

void test_appendWebcfgEncodedData()
{
size_t embeddeddocPackSize = -1;
void *embeddeddocdata = NULL;
//encode data
embeddeddocPackSize = appendWebcfgEncodedData(&embeddeddocdata, (void *)"abcd", 4, (void *)"efgh", 5);
CU_ASSERT_STRING_EQUAL(embeddeddocdata,"dbcdefgh");
CU_ASSERT_EQUAL(embeddeddocPackSize,9);
//test Msgpack Map (fixmap) MAX size
unsigned char byte[5]="abcd";
byte[0]=0xff;
embeddeddocPackSize = appendWebcfgEncodedData(&embeddeddocdata, (void *)byte, 4, (void *)"efgh", 5);
CU_ASSERT_EQUAL(embeddeddocPackSize,-1);
}

void test_webcfg_pack_appenddoc()
{
size_t appenddocPackSize = -1;
appenddoc_t *appenddata = NULL;
void *appenddocdata = NULL;
appenddocPackSize = webcfg_pack_appenddoc(appenddata, &appenddocdata);
CU_ASSERT_EQUAL(appenddocPackSize,-1);
}

void add_suites( CU_pSuite *suite )
{
*suite = CU_add_suite( "tests", NULL, NULL );
CU_add_test( *suite, "test writeToFileData", test_writeToFileData);
CU_add_test( *suite, "test webcfg_appendeddoc", test_webcfg_appendeddoc);
CU_add_test( *suite, "test appendWebcfgEncodedData", test_appendWebcfgEncodedData);
CU_add_test( *suite, "test webcfg_pack_appenddoc", test_webcfg_pack_appenddoc);
}

/*----------------------------------------------------------------------------*/
/* External Functions */
/*----------------------------------------------------------------------------*/
int main( int argc, char *argv[] )
{
unsigned rv = 1;
CU_pSuite suite = NULL;

(void ) argc;
(void ) argv;

if( CUE_SUCCESS == CU_initialize_registry() ) {
add_suites( &suite );

if( NULL != suite ) {
CU_basic_set_mode( CU_BRM_VERBOSE );
CU_basic_run_tests();
printf( "\n" );
CU_basic_show_failures( CU_get_failure_list() );
printf( "\n\n" );
rv = CU_get_number_of_tests_failed();
}

CU_cleanup_registry();

}

return rv;
}
Loading

0 comments on commit 47af39c

Please sign in to comment.