From cee43b8bd833602aa0156a2a247e2ff27284fd16 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 | 5 +++-- src/modules/phone.cpp | 13 +++++++------ src/modules/phone_data.h | 2 +- tests/modules/phone_test.cpp | 8 ++++++++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/include/faker-cxx/phone.h b/include/faker-cxx/phone.h index db26e03ae..d95aa39d8 100644 --- a/include/faker-cxx/phone.h +++ b/include/faker-cxx/phone.h @@ -65,10 +65,11 @@ enum class PhoneNumberCountryFormat; * @returns Random phone number based on country phone number template. * * @code + * faker::phone::number() // "234-532-654" * faker::phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494" * @endcode */ - FAKER_CXX_EXPORT std::string phoneNumberByCountry(PhoneNumberCountryFormat format); + FAKER_CXX_EXPORT std::string phoneNumberByCountry(std::optional format = std::nullopt); /** * @brief Returns IMEI number. @@ -325,6 +326,6 @@ enum class PhoneNumberCountryFormat WesternSahara, Yemen, Zambia, - Zimbabwe + Zimbabwe, }; } diff --git a/src/modules/phone.cpp b/src/modules/phone.cpp index fe55b4509..4668c0392 100644 --- a/src/modules/phone.cpp +++ b/src/modules/phone.cpp @@ -29,14 +29,15 @@ std::string phoneNumberByFormat(std::optional format) return helper::replaceSymbolWithNumber(selectedFormat); } -std::string phoneNumberByCountry(PhoneNumberCountryFormat format) +std::string phoneNumberByCountry(std::optional format) { - std::string countryFormat = phoneNumberFormatMap.at(format); + std::string countryFormat = (format)? phoneNumberFormatMap.at(*format) : + phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);; - if (countryFormat.empty()) - { - return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default); - } + // if (countryFormat.empty()) + // { + // return 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..b1403e40f 100644 --- a/tests/modules/phone_test.cpp +++ b/tests/modules/phone_test.cpp @@ -61,6 +61,14 @@ TEST_F(PhoneTest, NumberWithCountryFormat) ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber)); } +TEST_F(PhoneTest, NumberWithEmptyCountryFormat) +{ + const auto generatedPhoneNumber = phoneNumberByCountry(); + + EXPECT_FALSE(generatedPhoneNumber.empty()); + ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber)); +} + TEST_F(PhoneTest, IMEIGeneration) { auto generatedImei = imei();