-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gh-692: Using libuuid to generate uuids
- Loading branch information
1 parent
17531b6
commit a9d8ccb
Showing
6 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/internal_modules/roc_core/target_libuuid/roc_core/uuid.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright (c) 2023 Roc Streaming authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include "roc_core/uuid.h" | ||
|
||
#include "roc_core/panic.h" | ||
|
||
#include <uuid/uuid.h> | ||
|
||
namespace roc { | ||
namespace core { | ||
|
||
// Uses libuuid to generate the uuid. | ||
bool uuid_generare(char* buf, size_t buf_sz) { | ||
if (!buf) { | ||
roc_panic("uuid: buffer is null"); | ||
} | ||
if (buf_sz < UuidLen + 1) { | ||
roc_panic("uuid: buffer too small"); | ||
} | ||
|
||
uuid_t u; | ||
|
||
uuid_generate(u); | ||
uuid_unparse_lower(u, buf); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace core | ||
} // namespace roc |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2024 Roc Streaming authors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <CppUTest/TestHarness.h> | ||
|
||
#include "roc_core/uuid.h" | ||
|
||
namespace roc { | ||
namespace core { | ||
|
||
TEST_GROUP(uuid) {}; | ||
|
||
TEST(uuid, generate) { | ||
char a_uuid[UuidLen + 1] = {}; | ||
|
||
CHECK(uuid_generare(a_uuid, sizeof(a_uuid)) == true); | ||
CHECK(a_uuid[8] == '-'); | ||
CHECK(a_uuid[13] == '-'); | ||
CHECK(a_uuid[18] == '-'); | ||
CHECK(a_uuid[23] == '-'); | ||
CHECK(a_uuid[UuidLen] == '\0'); | ||
} | ||
|
||
TEST(uuid, generated_with_bigger_buffer) { | ||
char a_uuid[UuidLen + 1 + 4] = {}; | ||
|
||
CHECK(uuid_generare(a_uuid, sizeof(a_uuid)) == true); | ||
CHECK(a_uuid[8] == '-'); | ||
CHECK(a_uuid[13] == '-'); | ||
CHECK(a_uuid[18] == '-'); | ||
CHECK(a_uuid[23] == '-'); | ||
CHECK(a_uuid[UuidLen] == '\0'); | ||
} | ||
|
||
} // namespace core | ||
} // namespace roc |