mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Remove unneeded functions, add UuidFromString.
This commit is contained in:
@@ -12,74 +12,25 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "internal/platform/implementation/linux/utils.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "absl/strings/ascii.h"
|
||||
#include "internal/platform/implementation/linux/utils.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace linux {
|
||||
|
||||
TEST(UtilsTests, MacAddressToString) {
|
||||
// Arrange
|
||||
const uint64_t input = 0x000034363bc70c71;
|
||||
std::string expected = "34:36:3B:C7:0C:71";
|
||||
TEST(UtilsTests, UuidFromStringRoundTrip) {
|
||||
std::string input = "b5209043-f493-4b38-8c34-810aa3cd1407";
|
||||
|
||||
// Act
|
||||
std::string result = uint64_to_mac_address_string(input);
|
||||
auto nearby_uuid = UuidFromString(input);
|
||||
EXPECT_TRUE(nearby_uuid.has_value());
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
|
||||
EXPECT_EQ(absl::AsciiStrToLower(std::string{*nearby_uuid}),
|
||||
"b5209043-f493-4b38-8c34-810aa3cd1407");
|
||||
}
|
||||
|
||||
TEST(UtilsTests, StringToMacAddress) {
|
||||
// Arrange
|
||||
std::string input = "34:36:3B:C7:8C:71";
|
||||
const uint64_t expected = 0x000034363bc78c71;
|
||||
|
||||
// Act
|
||||
uint64_t result = mac_address_string_to_uint64(input);
|
||||
|
||||
// Assert
|
||||
EXPECT_EQ(result, expected);
|
||||
}
|
||||
|
||||
constexpr absl::string_view kIpDotdecimal{"192.168.1.37"};
|
||||
|
||||
constexpr char kIp4Bytes[] = {(char)192, (char)168, (char)1, (char)37};
|
||||
|
||||
TEST(UtilsTests, Ip4BytesToDotdecimal) {
|
||||
std::string result =
|
||||
ipaddr_4bytes_to_dotdecimal_string(absl::string_view(kIp4Bytes));
|
||||
|
||||
EXPECT_EQ(result, kIpDotdecimal);
|
||||
}
|
||||
|
||||
TEST(UtilsTests, IpDotdecimalTo4Bytes) {
|
||||
std::string result =
|
||||
ipaddr_dotdecimal_to_4bytes_string(std::string(kIpDotdecimal));
|
||||
|
||||
EXPECT_EQ(result, std::string(kIp4Bytes, 4));
|
||||
}
|
||||
|
||||
/*
|
||||
TEST(UtilsTests, ConvertBetweenWinrtGuidAndNearbyUuidSuccessfully) {
|
||||
Uuid uuid(0x123e4567e89b12d3, 0xa456426614174000);
|
||||
winrt::guid guid("{123e4567-e89b-12d3-a456-426614174000}");
|
||||
|
||||
EXPECT_EQ(uuid, winrt_guid_to_nearby_uuid(guid));
|
||||
EXPECT_EQ(nearby_uuid_to_winrt_guid(uuid), guid);
|
||||
EXPECT_TRUE(is_nearby_uuid_equal_to_winrt_guid(uuid, guid));
|
||||
}
|
||||
|
||||
TEST(UtilsTests, CompareWinrtGuidAndNearbyUuidSuccessfully) {
|
||||
Uuid uuid(0x123e4567e89b12d3, 0xa456426614174000);
|
||||
winrt::guid guid("123e4567-e89b-12d3-a456-426614074000");
|
||||
|
||||
EXPECT_NE(uuid, winrt_guid_to_nearby_uuid(guid));
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace linux
|
||||
} // namespace nearby
|
||||
|
||||
Reference in New Issue
Block a user