From d102574d8d6a1d161124cff36c6536e82d272284 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Thu, 25 Jul 2024 01:59:18 +0200 Subject: [PATCH] test: phone module testcase added * test case added to phone module for code coverage Signed-off-by: Guru Mehar Rachaputi --- include/faker-cxx/phone.h | 3 ++- src/modules/phone.cpp | 4 ++-- src/modules/phone_data.h | 2 +- tests/modules/phone_test.cpp | 10 ++++++++++ 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/include/faker-cxx/phone.h b/include/faker-cxx/phone.h index db26e03ae..d2fe194f2 100644 --- a/include/faker-cxx/phone.h +++ b/include/faker-cxx/phone.h @@ -325,6 +325,7 @@ enum class PhoneNumberCountryFormat WesternSahara, Yemen, Zambia, - Zimbabwe + Zimbabwe, + Empty }; } diff --git a/src/modules/phone.cpp b/src/modules/phone.cpp index fe55b4509..d7ed003d6 100644 --- a/src/modules/phone.cpp +++ b/src/modules/phone.cpp @@ -31,11 +31,11 @@ std::string phoneNumberByFormat(std::optional format) std::string phoneNumberByCountry(PhoneNumberCountryFormat format) { - std::string countryFormat = phoneNumberFormatMap.at(format); + std::string countryFormat = (format == PhoneNumberCountryFormat::Empty)? "" : phoneNumberFormatMap.at(format); if (countryFormat.empty()) { - return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default); + countryFormat = phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default); } return helper::replaceSymbolWithNumber(countryFormat); diff --git a/src/modules/phone_data.h b/src/modules/phone_data.h index 624dc7a42..25759d455 100644 --- a/src/modules/phone_data.h +++ b/src/modules/phone_data.h @@ -271,7 +271,7 @@ const auto phoneNumbers = std::to_array({ "+212 (###) ####", // Western Sahara "+967 (###) ###-####", // Yemen "+260 (###) ###-####", // Zambia - "+263 (###) ####" // Zimbabwe + "+263 (###) ####", // Zimbabwe }); } diff --git a/tests/modules/phone_test.cpp b/tests/modules/phone_test.cpp index ec0df24d7..13740fe0c 100644 --- a/tests/modules/phone_test.cpp +++ b/tests/modules/phone_test.cpp @@ -61,6 +61,16 @@ TEST_F(PhoneTest, NumberWithCountryFormat) ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber)); } +TEST_F(PhoneTest, NumberWithEmptyCountryFormat) +{ + const auto generatedPhoneNumber = phoneNumberByCountry(PhoneNumberCountryFormat::Empty); + + std::cout << generatedPhoneNumber << std::endl; + + EXPECT_FALSE(generatedPhoneNumber.empty()); + ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber)); +} + TEST_F(PhoneTest, IMEIGeneration) { auto generatedImei = imei();