From 34f90be0a320e39932dd29ed343c049031303d55 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Fri, 1 Jun 2012 01:58:19 -0400 Subject: [PATCH] Added test file --- source/opts.c | 53 +++++++++++++++++++++++++++++++++++++++++++-- source/opts.h | 33 +++++++++++++++++++++++++++- tests/test_opts.cpp | 20 +++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 tests/test_opts.cpp diff --git a/source/opts.c b/source/opts.c index 17bc70f..dfc901c 100644 --- a/source/opts.c +++ b/source/opts.c @@ -1,6 +1,55 @@ +#include +#include #include "opts.h" -int foo(void) +OptionList_T* OPTS_ParseOptions( int argc, char** argv ) { - return 42; + ParserContext_T ctx; + ctx.options = 0; + + //while( ctx.tok_stream.stream.cur_char != EOF ) + //{ + // OPTS_ParseOption( &(ctx) ); + //} + + return ctx.options; +} + +OptionList_T* OPTS_ParseOption( ParserContext_T* ctx ) +{ + return NULL; +} + +char* OPTS_NextToken( TokenContext_T* ctx ) +{ + return NULL; +} + +char OPTS_NextCharacter( StreamContext_T* ctx ) +{ + char current = EOF; + + if( ctx->line_idx < ctx->arg_count ) + { + ctx->col_idx++; + + if(ctx->arg_vect[ ctx->line_idx ][ ctx->col_idx ] == '\0') + { + ctx->col_idx = 0; + ctx->line_idx++; + } + + if( ctx->line_idx < ctx->arg_count ) + { + current = ctx->arg_vect[ ctx->line_idx ][ ctx->col_idx ]; + } + } + + return current; } + +void OPTS_FreeOptionList( OptionList_T* opts ) +{ + +} + diff --git a/source/opts.h b/source/opts.h index 513dd89..f8dbf27 100644 --- a/source/opts.h +++ b/source/opts.h @@ -1,6 +1,37 @@ #ifndef OPTS_H #define OPTS_H -int foo(void); +typedef struct { + int line_idx; + int col_idx; + int arg_count; + char** arg_vect; +} StreamContext_T; + +typedef struct { + StreamContext_T stream; + char* cur_token; +} TokenContext_T; + +typedef struct OptionList { + char** key; + char** val; + struct OptionList* next; +} OptionList_T; + +typedef struct { + TokenContext_T tok_stream; + OptionList_T* options; +} ParserContext_T; + +OptionList_T* OPTS_ParseOptions( int argc, char** argv ); + +OptionList_T* OPTS_ParseOption( ParserContext_T* ctx ); + +char* OPTS_NextToken( TokenContext_T* ctx ); + +char OPTS_NextCharacter( StreamContext_T* ctx ); + +void OPTS_FreeOptionList( OptionList_T* options ); #endif diff --git a/tests/test_opts.cpp b/tests/test_opts.cpp new file mode 100644 index 0000000..13e99a8 --- /dev/null +++ b/tests/test_opts.cpp @@ -0,0 +1,20 @@ +// Unit Test Framework Includes +#include "UnitTest++.h" + +// File To Test +#include "opts.h" + +using namespace UnitTest; + +//----------------------------------------------------------------------------- +// Begin Unit Tests +//----------------------------------------------------------------------------- +namespace { + //------------------------------------------------------------------------- + // Test NextCharacter Function + //------------------------------------------------------------------------- + TEST(Verify_NextCharacter_Can_Loop_Through_Characters) + { + StreamContext_T ctx; + } +} -- 2.54.0