Skip to content

Commit

Permalink
Merge branch 'feature/uuid-fix' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoblath committed Sep 19, 2024
2 parents 8fc0acd + f0b1a54 commit 0b23732
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
18 changes: 2 additions & 16 deletions library/uuid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,7 @@ namespace dripline

if( a_id_str.empty() ) return generate_nil_uuid();

try
{
return t_gen( a_id_str );
}
catch(...)
{
throw;
}
return t_gen( a_id_str );
}

uuid_t DRIPLINE_API uuid_from_string( const char* a_id_str )
Expand All @@ -50,14 +43,7 @@ namespace dripline

if( strcmp( a_id_str, "" ) == 0 ) return generate_nil_uuid();

try
{
return t_gen( a_id_str );
}
catch(...)
{
throw;
}
return t_gen( a_id_str );
}

uuid_t DRIPLINE_API uuid_from_string( const std::string& a_id_str, bool& a_valid_flag )
Expand Down
3 changes: 2 additions & 1 deletion library/uuid.hh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ namespace dripline

/*!
Converts a string to a UUID object.
@return the uuid_t object representing the given string, or a nil UUID if the string is not a valid UUID
Throws a std::runtime_error if the string is an invalid UUID.
@return the uuid_t object representing the given string
@param a_id_str The input UUID represented as a string.
Valid formats are `hhhhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhhhh`,
where each `h` is a case-insensitive hexidecimal character,
Expand Down
1 change: 1 addition & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set( testing_SOURCES
test_service.cc
test_specifier.cc
test_throw_reply.cc
test_uuid.cc
test_version_store.cc
)

Expand Down
45 changes: 45 additions & 0 deletions testing/test_uuid.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* test_uuid.cc
*
* Created on: Sept 18, 2024
* Author: N.S. Oblath
*/

#include "uuid.hh"

#include "catch.hpp"

TEST_CASE( "uuid", "[message]" )
{
REQUIRE_NOTHROW( dripline::generate_nil_uuid() );
REQUIRE_NOTHROW( dripline::generate_random_uuid() );

REQUIRE_THROWS_AS( dripline::uuid_from_string( "blah" ), std::runtime_error );

std::string t_test_string_1( "AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE" );
dripline::uuid_t t_test_uuid_1;
REQUIRE_NOTHROW( t_test_uuid_1 = dripline::uuid_from_string( t_test_string_1 ) );
REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_1), Catch::CaseSensitive::No) );

std::string t_test_string_2( "{AAAAAAAA-BBBB-CCCC-DDDD-EEEEEEEEEEEE}" );
dripline::uuid_t t_test_uuid_2;
REQUIRE_NOTHROW( t_test_uuid_2 = dripline::uuid_from_string( t_test_string_2 ) );
// compare to t_test_string_1 because the to_string conversion adds dashes and has no braces
REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_2), Catch::CaseSensitive::No) );

std::string t_test_string_3( "AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE" );
dripline::uuid_t t_test_uuid_3;
REQUIRE_NOTHROW( t_test_uuid_3 = dripline::uuid_from_string( t_test_string_3 ) );
// compare to t_test_string_1 because the to_string conversion adds dashes and has no braces
REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_3), Catch::CaseSensitive::No) );

std::string t_test_string_4( "{AAAAAAAABBBBCCCCDDDDEEEEEEEEEEEE}" );
dripline::uuid_t t_test_uuid_4;
REQUIRE_NOTHROW( t_test_uuid_4 = dripline::uuid_from_string( t_test_string_4 ) );
// compare to t_test_string_1 because the to_string conversion adds dashes and has no braces
REQUIRE_THAT( t_test_string_1, Catch::Equals(dripline::string_from_uuid(t_test_uuid_4), Catch::CaseSensitive::No) );
}




0 comments on commit 0b23732

Please sign in to comment.