Skip to content

Commit 2e3ae39

Browse files
authored
UUID ToString & test (aws#118)
UUID ToString & test awslabs/aws-crt-cpp#116
1 parent 01cb75e commit 2e3ae39

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

source/UUID.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ namespace Aws
4848
String UUID::ToString() const
4949
{
5050
String uuidStr;
51-
uuidStr.reserve(AWS_UUID_STR_LEN);
52-
51+
uuidStr.resize(AWS_UUID_STR_LEN);
5352
auto outBuf = ByteBufFromEmptyArray(reinterpret_cast<const uint8_t *>(uuidStr.data()), uuidStr.capacity());
5453
aws_uuid_to_str(&m_uuid, &outBuf);
54+
uuidStr.resize(outBuf.len);
5555
return uuidStr;
5656
}
5757

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ add_test_case(TestProviderDefaultChainGet)
4444
add_test_case(HttpRequestTestCreateDestroy)
4545
add_test_case(Sigv4SigningTestCreateDestroy)
4646
add_test_case(Sigv4SigningTestSimple)
47+
add_test_case(UUIDToString)
4748

4849
generate_cpp_test_driver(${TEST_BINARY_NAME})
4950

tests/UUIDTest.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
/*
3+
* Copyright 2010-2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License").
6+
* You may not use this file except in compliance with the License.
7+
* A copy of the License is located at
8+
*
9+
* http://aws.amazon.com/apache2.0
10+
*
11+
* or in the "license" file accompanying this file. This file is distributed
12+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
* express or implied. See the License for the specific language governing
14+
* permissions and limitations under the License.
15+
*/
16+
#include <aws/crt/Api.h>
17+
#include <aws/crt/UUID.h>
18+
19+
#include <aws/testing/aws_test_harness.h>
20+
#include <iostream>
21+
#include <utility>
22+
23+
static int s_UUIDToString(Aws::Crt::Allocator *allocator, void *ctx)
24+
{
25+
(void)ctx;
26+
Aws::Crt::ApiHandle apiHandle(allocator);
27+
Aws::Crt::UUID Uuid;
28+
Aws::Crt::String uuidStr = Uuid.ToString();
29+
ASSERT_TRUE(uuidStr.length() != 0);
30+
ASSERT_TRUE(Uuid == Aws::Crt::UUID(uuidStr));
31+
32+
return AWS_ERROR_SUCCESS;
33+
}
34+
35+
AWS_TEST_CASE(UUIDToString, s_UUIDToString)

0 commit comments

Comments
 (0)