Skip to content

Commit

Permalink
Add Lua manager test
Browse files Browse the repository at this point in the history
  • Loading branch information
idzm committed Nov 11, 2024
1 parent 8ad9d90 commit 72f653b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions common/lua_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,20 @@ int check_file( const char* file_name, char* err_str )
strcpy( err_str, "" );

FILE *f = fopen( file_name, "r");
if ( 0 == f )
if ( !f )
{
G_LOG->error( err_str, "File \"%s\" not found!", file_name );
return -1;
}
int version = 0;

char str[ 100 ] = "";
if ( char* res = fgets(str, sizeof(str), f); res != 0 )
if ( char str[ 100 ] = ""; fgets( str, sizeof( str ), f ) )
{
int err = sscanf( str, "--version = %d", &version );
}

fclose( f );
f = 0;
f = nullptr;

if ( G_DEBUG )
{
Expand Down
15 changes: 15 additions & 0 deletions test/lua_manager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,18 @@ TEST( lua_manager, error_trace )
EXPECT_NE( 0, G_LUA_MANAGER->void_exec_lua_method( "t", "no_exist3", "error_trace" ) );
G_LUA_MANAGER->free_Lua();
}

TEST( lua_manager, check_file )
{
auto FILE_VERSION = 10;
char err_str[ 500 ] = {};
const char* FILE_NAME = "test.lua";
if ( FILE* f = std::fopen( FILE_NAME, "w+" ) )
{
std::fprintf( f, "--version = %d\n", FILE_VERSION );
std::fclose( f );
}

auto res = check_file( FILE_NAME, err_str );
EXPECT_EQ( res, FILE_VERSION );
}

0 comments on commit 72f653b

Please sign in to comment.