diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ed53ba4f..6c8664486 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ if (NOT USE_SYSTEM_DEPENDENCIES) include(CheckCXXSourceCompiles) check_cxx_source_compiles("#include \nint main(){ auto var = std::format(\"{}\", \"Hello\"); return 0; }" HAS_STD_FORMAT) -endif() +endif () set(LIBRARY_NAME faker-cxx) @@ -55,7 +55,6 @@ set(FAKER_SOURCES src/modules/computer/Computer.cpp src/modules/vehicle/Vehicle.cpp src/modules/science/Science.cpp - src/modules/structure/Structure.cpp ) add_library(${LIBRARY_NAME} ${FAKER_SOURCES}) @@ -92,7 +91,7 @@ install(EXPORT ${LIBRARY_NAME}-targets if (HAS_STD_FORMAT AND NOT USE_SYSTEM_DEPENDENCIES) target_compile_definitions(${LIBRARY_NAME} PRIVATE HAS_STD_FORMAT) -elseif(USE_SYSTEM_DEPENDENCIES) +elseif (USE_SYSTEM_DEPENDENCIES) find_package(fmt REQUIRED) target_link_libraries(${LIBRARY_NAME} PRIVATE fmt::fmt) else () diff --git a/README.md b/README.md index 860000e3d..9e398b97d 100644 --- a/README.md +++ b/README.md @@ -14,12 +14,15 @@ ## đŸŽ¯ Goal -The goal of Faker C++ is to provide a library similar to [Faker.js](https://github.com/faker-js/faker) for C++ community. Faker C++ helps with the creation of realistic and customizable fake data for testing and development purposes within C++ applications. +The goal of Faker C++ is to provide a library similar to [Faker.js](https://github.com/faker-js/faker) for C++ +community. Faker C++ helps with the creation of realistic and customizable fake data for testing and development +purposes within C++ applications. ## Usage and Documentation To properly use Faker C++ you must first consume the Faker library (see Consuming Library with CMake). -Once that is done, you need to include the proper header files depending on the module you wish to generate data from. The module header file names can be found in [docs](https://cieslarmichal.github.io/faker-cxx). +Once that is done, you need to include the proper header files depending on the module you wish to generate data from. +The module header file names can be found in [docs](https://cieslarmichal.github.io/faker-cxx). Below is an example of how to use Faker C++ in your code. @@ -42,7 +45,7 @@ int main() std::cout << id << std::endl; // 58018063-ce5a-4fa7-adfd-327eb2e2d9a5 std::cout << email << std::endl; // Lois_Hauck@hotmail.com std::cout << password << std::endl; // @cWLwgM#Knalxeb - std::cout << city << std::endl; // Sayreville + std::cout << city << std::endl; // Sayre ville std::cout << streetAddress << std::endl; // 1716 Harriet Alley return 0; @@ -56,8 +59,9 @@ int main() - 📖 Book - book title, genre, author, publisher, ISBN - 🎨 Color - color names, rgb, hex, hcl - 🛒 Commerce - commerce department, product name, sku, price -- đŸĸ Company - company name, type, industry, catch phrase, buzz phrase +- đŸĸ Company - company name, type, industry, catchphrase, buzz phrase - đŸ–Ĩī¸ Computer - type, manufacturer, model, CPU info, GPU info +- 🔐 Crypto - sha256, md5 - 💾 Database - column names, column types, database engines - ℹī¸ Datatype - booleans - 📅 Date - past, future dates @@ -74,11 +78,12 @@ int main() - đŸŽĨ Movie - actors, actresses, genres, movie titles - đŸŽļ Music - artists, song names, genres - đŸ”ĸ Number - random integers, floating point numbers -- 🧑 Person - first, last names, job titles, hobby, genders, sex, nationalitiy, language +- 🧑 Person - first, last names, job titles, hobby, genders, sex, nationality, language - 📞 Phone - phone number, IMEI - âšŊ Sport - sport names, athletes, events - đŸ”ĸ String - uuids, alphanumeric, numeric, hexadecimal - đŸ’ģ System - file paths, file extensions, file names, directories, semantic version +- 🚗 Vehicle - vehicle types, makes, models, fuel types, license plates - 🎮 Video game - title, genre, platform, studio - 🌤ī¸ Weather - temperature, pressure, humidity, weather description - đŸ’Ŧ Word - sample words, nouns, verbs @@ -126,12 +131,14 @@ If you have any confusion please refer to the respective guides. - GTest (set `BUILD_FAKER_CXX_TESTS=OFF` CMake flag to disable this dependency) - fmt (only for compilers that don't support std::format) -In order to use external dependencies installed in your system, you can set the `USE_SYSTEM_DEPENDENCIES` CMake flag to `ON`. +In order to use external dependencies installed in your system, you can set the `USE_SYSTEM_DEPENDENCIES` CMake flag +to `ON`. ## ✨ Contributing We would love it if you contributed to Faker C++! 🚀 -Before contributing please review our [CONTRIBUTING](https://github.com/cieslarmichal/faker-cxx/blob/main/CONTRIBUTING.md) guide. +Before contributing please review +our [CONTRIBUTING](https://github.com/cieslarmichal/faker-cxx/blob/main/CONTRIBUTING.md) guide. Additionally, we encourage you to join our [Discord Channel](https://discord.gg/h2ur8H6mK6) for contributors. diff --git a/include/faker-cxx/Structure.h b/include/faker-cxx/Structure.h deleted file mode 100644 index e8fb74045..000000000 --- a/include/faker-cxx/Structure.h +++ /dev/null @@ -1,355 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -enum class StructureToken; - -class Structure -{ -public: - /** - * @brief Get a json string based on input - * - * @return a json string based on user selected tokens - * - * @code - * std::map testTokens; - * testTokens.emplace("Airport name", faker::StructureToken::AirlineAirportName); - * testTokens.emplace("Bird name", faker::StructureToken::AnimalBird); - * testTokens.emplace("Actor name", faker::StructureToken::MovieActor); - * testTokens.emplace("Book title", faker::StructureToken::BookTitle); - * Structure::json(testTokens) // {"FoodName":"Cajun Shrimp - * Pasta","airlineType":"narrowbody","airportName":"Brisbane International Airport"} - * @endcode - */ - static std::string json(const std::map& items); - /** - * @brief Get a csv string based on input - * - * @return a josn csv based on user selected tokens and rows - * - * @code - * std::map testTokens; - * testTokens.emplace("Airport name", faker::StructureToken::AirlineAirportName); - * testTokens.emplace("Bird name", faker::StructureToken::AnimalBird); - * testTokens.emplace("Actor name", faker::StructureToken::MovieActor); - * testTokens.emplace("Book title", faker::StructureToken::BookTitle); - * Structure::csv(testTokens,2) // FoodName,airlineType,airportName - Lobster Roll,widebody,Soekarno-Hatta International Airport - Pierogi,widebody,Brasilia-Presidente Juscelino Kubitschek International Airport - * @endcode - */ - static std::string csv(const std::map& items, unsigned int rows); -}; - -enum class StructureToken -{ - // Airline module - AirlineAircraftType, - AirlineAirplaneName, - AirlineAirplaneCode, - AirlineAirlineName, - AirlineAirlineCode, - AirlineAirportName, - AirlineAirportCode, - AirlineSeat, - AirlineRecordLocator, - AirlineFlightNumber, - - // Animal module - AnimalBear, - AnimalBird, - AnimalCat, - AnimalCetacean, - AnimalCow, - AnimalCrocodilia, - AnimalDog, - AnimalFish, - AnimalHorse, - AnimalInsect, - AnimalLion, - AnimalRabbit, - AnimalRodent, - AnimalSnake, - AnimalType, - - // Book module - BookTitle, - BookGenre, - BookAuthor, - BookPublisher, - BookIsbn, - - // Color module - ColorName, - ColorRGB, - ColorHEX, - ColorHSL, - ColorLCH, - ColorCMYK, - - // Commerce module - CommerceDepartment, - CommercePrice, - CommerceSku, - CommerceProductAdjective, - CommerceProductMaterial, - CommerceProductName, - CommerceProductFullName, - CommerceEAN13, - CommerceEAN8, - CommerceISBN13, - CommerceISBN10, - - // Company module - CompanyName, - CompanyType, - CompanyIndustry, - CompanyBuzzPhrase, - CompanyBuzzAdjective, - CompanyBuzzNoun, - CompanyBuzzVerb, - CompanyCatchPhrase, - CompanyCtachPhraseAdjective, - CompanyCatchPhraseDescriptor, - CompanyCatchPhraseNoun, - - // Computer module - ComputerType, - ComputerManufacture, - ComputerModel, - ComputerCPUManufacture, - ComputerCPUType, - ComputerCPUModel, - ComputerGPUManufacture, - ComputerGPUType, - ComputerGPUModel, - - // Crypto module - CryptoSHA256, - CryptoMD5, - - // Database module - DatabaseColumnName, - DatabaseColumnType, - DatabaseCollation, - DatabaseEngine, - DatabaseMongoDBObjectId, - - // Datatype module - DatatypeBoolean, - - // Date module ISO and Timestamp - DatePastDateISO, - DatePastDateTimestamp, - DatefutureDateISO, - DatefutureDateTimestamp, - DateRecentDateISO, - DateRecentDateTimestamp, - DateSoonDateISO, - DateSoonDateTimestamp, - DateBirthdateByAgeISO, - DateBirthdateByAgeTimestamp, - DateBirthdateByYearISO, - DateBirthdateByYearTimestamp, - DateWeekdayName, - DateWeekdayAbbreviatedName, - DateMontName, - DateMonthAbbreviatedName, - - // Finance module - FinanceCurrencyName, - FinanceCurrencyCode, - FinanceCurrencySymbol, - FinanceAccountType, - FinanceAmount, - FinanceIban, - FinanceBic, - FinanceAccountNumber, - FinancePin, - FinanceRoutingNumber, - FinanceCreditCardNumber, - FinanceCreditCardCvv, - FinanceBitcoinAddress, - FinanceLitecoinAddress, - FinanceEthereumAddress, - - // Food module - FoodAlcoholicBeverage, - FoodGrain, - FoodMilkProduct, - FoodFruit, - FoodMeat, - FoodSeafood, - FoodVegetable, - FoodOil, - FoodNut, - FoodSeed, - FoodSugarProduct, - FoodNonAlcoholicBeverage, - FoodDishName, - FoodFoodCategory, - - // Git module - GitBranch, - GitCommitDate, - GitCommitEntry, - GitCommitMessage, - GitCommitSha, - - // Hacker module - HackerAbbreviation, - HackerAdjective, - HackerNoun, - HackerVerb, - HackerIngverb, - HackerPhrase, - - // Image module - ImageImageURL, - ImageGitHubAvatarURL, - ImageDimensions, - - // Internet module - InternetUsername, - InternetEmail, - InternetExampleEmail, - InternetPassword, - InternetEmoji, - InternetProtocol, - InternetHttpMethod, - InternetHttpRequestHeader, - InternetHttpResponseHeader, - InternetHttpMediaType, - InternetIpv4, - InternetIpv6, - InternetMac, - InternetURL, - InternetDomainName, - InternetDomainWord, - InternetDomainSuffix, - - // Location module - LocationCountry, - LocationCountryCode, - LocationState, - LocationCity, - LocationZipCode, - LocationStreetAddress, - LocationStreet, - LocationBuildingNumber, - LocationSecondaryAddress, - LocationLatitude, - LocationLongitude, - LocationDirection, - LocationTimeZone, - - // Lorem module - LoremWord, - LoremWords, - LoremSentence, - LoremSentences, - LoremSlung, - LoremParagraph, - LoremParagraphs, - - // Medicine module - MedicineCondition, - MedicineMedicalTest, - MedicineSpecialty, - - // Movie module - MovieGenre, - MovieMovieTitle, - MovieTvShow, - MovieDirector, - MovieActor, - MovieActress, - - // Music module - MusicArtist, - MusicGenre, - MusicSongName, - - // Person module - PersonFirstName, - PersonLastName, - PersonMiddleName, - PersonFullName, - PersonPrefix, - PersonSuffix, - PersonSex, - PersonGender, - PersonJobTitle, - PersonJobDescriptor, - PersonJobArea, - PersonJobType, - PersonHoby, - PersonLanguage, - PersonNationality, - PersonWesternZodiac, - PersonChineseZodiac, - - // Phone module - PhoneNumber, - PhonePlatform, - PhoneModelName, - PhoneManufacturer, - PhoneIMEI, - - // Sport module - SportSport, - SportSoccerTeam, - SportMaleAthelete, - SportFemaleAthlete, - SportSportEvent, - - // System module - SystemFileName, - SystemFileExtension, - SystemCommonFileName, - SystemCommonFileExtension, - SystemMimeType, - SystemCommonFileType, - SystemFileType, - SystemDirectoryPath, - SystemFilePath, - SystemSemver, - SystemNetworkInterface, - SystemCron, - - // VideoGame module - VideoGameGameTitle, - VideoGameGenre, - VideoGamePlatform, - VideoGameStudioName, - - // Weather module - WeatherTemperatureMetric, - WeatherTemperatureImperial, - WeatherPressureMetric, - WeatherPressureImperial, - WeatherVisibilityMetric, - WeatherVisibilityImperial, - WeatherWindSpeedMetric, - WeatherWindSpeedImperial, - WeatherUvIndex, - WeatherHumidity, - WeatherWeatherDescription, - WeatherCloudCover, - - // Word module - WordSample, - WordWords, - WordAdjective, - WordAdverb, - WordConjunction, - WordInterjection, - WordNoun, - WordPreposition, - WordVerb, -}; -} diff --git a/src/modules/structure/Structure.cpp b/src/modules/structure/Structure.cpp deleted file mode 100644 index b860a12e5..000000000 --- a/src/modules/structure/Structure.cpp +++ /dev/null @@ -1,388 +0,0 @@ -#include "faker-cxx/Structure.h" - -#include - -#include "faker-cxx/Airline.h" -#include "faker-cxx/Animal.h" -#include "faker-cxx/Book.h" -#include "faker-cxx/Color.h" -#include "faker-cxx/Commerce.h" -#include "faker-cxx/Company.h" -#include "faker-cxx/Computer.h" -#include "faker-cxx/Crypto.h" -#include "faker-cxx/Database.h" -#include "faker-cxx/Datatype.h" -#include "faker-cxx/Date.h" -#include "faker-cxx/Finance.h" -#include "faker-cxx/Food.h" -#include "faker-cxx/Git.h" -#include "faker-cxx/Hacker.h" -#include "faker-cxx/Image.h" -#include "faker-cxx/Internet.h" -#include "faker-cxx/Location.h" -#include "faker-cxx/Lorem.h" -#include "faker-cxx/Medicine.h" -#include "faker-cxx/Movie.h" -#include "faker-cxx/Music.h" -#include "faker-cxx/Person.h" -#include "faker-cxx/Phone.h" -#include "faker-cxx/Sport.h" -#include "faker-cxx/String.h" -#include "faker-cxx/System.h" -#include "faker-cxx/VideoGame.h" -#include "faker-cxx/Weather.h" -#include "faker-cxx/Word.h" - -namespace faker -{ -const std::map> moduleFunctions = { - {StructureToken::AirlineAircraftType, []() { return Airline::aircraftType(); }}, - {StructureToken::AirlineAirplaneName, []() { return Airline::airplane().name; }}, - {StructureToken::AirlineAirplaneCode, []() { return Airline::airplane().iataTypeCode; }}, - {StructureToken::AirlineAirplaneName, []() { return Airline::airplane().name; }}, - {StructureToken::AirlineAirplaneCode, []() { return Airline::airplane().iataTypeCode; }}, - {StructureToken::AirlineAirlineName, []() { return Airline::airline().name; }}, - {StructureToken::AirlineAirlineCode, []() { return Airline::airline().iataCode; }}, - {StructureToken::AirlineAirportName, []() { return Airline::airport().name; }}, - {StructureToken::AirlineAirportCode, []() { return Airline::airport().iataCode; }}, - {StructureToken::AirlineSeat, []() { return Airline::seat(Airline::AircraftType()); }}, - {StructureToken::AirlineRecordLocator, []() { return Airline::recordLocator(); }}, - {StructureToken::AirlineFlightNumber, []() { return Airline::flightNumber(false, 4); }}, - - {StructureToken::AnimalBear, []() { return Animal::bear(); }}, - {StructureToken::AnimalBird, []() { return Animal::bird(); }}, - {StructureToken::AnimalCat, []() { return Animal::cat(); }}, - {StructureToken::AnimalCetacean, []() { return Animal::cetacean(); }}, - {StructureToken::AnimalCow, []() { return Animal::cow(); }}, - {StructureToken::AnimalCrocodilia, []() { return Animal::crocodile(); }}, - {StructureToken::AnimalDog, []() { return Animal::dog(); }}, - {StructureToken::AnimalFish, []() { return Animal::fish(); }}, - {StructureToken::AnimalHorse, []() { return Animal::horse(); }}, - {StructureToken::AnimalInsect, []() { return Animal::insect(); }}, - {StructureToken::AnimalLion, []() { return Animal::lion(); }}, - {StructureToken::AnimalRabbit, []() { return Animal::rabbit(); }}, - {StructureToken::AnimalRodent, []() { return Animal::rodent(); }}, - {StructureToken::AnimalSnake, []() { return Animal::snake(); }}, - {StructureToken::AnimalType, []() { return Animal::type(); }}, - - {StructureToken::BookTitle, []() { return Book::title(); }}, - {StructureToken::BookGenre, []() { return Book::genre(); }}, - {StructureToken::BookAuthor, []() { return Book::author(); }}, - {StructureToken::BookPublisher, []() { return Book::publisher(); }}, - {StructureToken::BookIsbn, []() { return Book::isbn(); }}, - - {StructureToken::ColorName, []() { return Color::name(); }}, - {StructureToken::ColorRGB, []() { return Color::rgb(); }}, - {StructureToken::ColorHEX, []() { return Color::hex(); }}, - {StructureToken::ColorHSL, []() { return Color::hsl(); }}, - {StructureToken::ColorLCH, []() { return Color::lch(); }}, - {StructureToken::ColorCMYK, []() { return Color::cmyk(); }}, - - {StructureToken::CommerceDepartment, []() { return Commerce::department(); }}, - {StructureToken::CommercePrice, []() { return Commerce::price(); }}, - {StructureToken::CommerceSku, []() { return Commerce::sku(); }}, - {StructureToken::CommerceProductAdjective, []() { return Commerce::productAdjective(); }}, - {StructureToken::CommerceProductMaterial, []() { return Commerce::productMaterial(); }}, - {StructureToken::CommerceProductName, []() { return Commerce::productName(); }}, - {StructureToken::CommerceProductFullName, []() { return Commerce::productFullName(); }}, - {StructureToken::CommerceEAN13, []() { return Commerce::EAN13(); }}, - {StructureToken::CommerceEAN8, []() { return Commerce::EAN8(); }}, - {StructureToken::CommerceISBN13, []() { return Commerce::ISBN13(); }}, - {StructureToken::CommerceISBN10, []() { return Commerce::ISBN10(); }}, - - {StructureToken::CompanyName, []() { return Company::name(); }}, - {StructureToken::CompanyType, []() { return Company::type(); }}, - {StructureToken::CompanyIndustry, []() { return Company::industry(); }}, - {StructureToken::CompanyBuzzPhrase, []() { return Company::buzzPhrase(); }}, - {StructureToken::CompanyBuzzAdjective, []() { return Company::buzzAdjective(); }}, - {StructureToken::CompanyBuzzNoun, []() { return Company::buzzNoun(); }}, - {StructureToken::CompanyBuzzVerb, []() { return Company::buzzVerb(); }}, - {StructureToken::CompanyCatchPhrase, []() { return Company::catchPhrase(); }}, - {StructureToken::CompanyCtachPhraseAdjective, []() { return Company::catchPhraseAdjective(); }}, - {StructureToken::CompanyCatchPhraseDescriptor, []() { return Company::catchPhraseDescriptor(); }}, - {StructureToken::CompanyCatchPhraseNoun, []() { return Company::catchPhraseNoun(); }}, - - {StructureToken::ComputerManufacture, []() { return Computer::manufacture(); }}, - {StructureToken::ComputerModel, []() { return Computer::model(); }}, - {StructureToken::ComputerCPUManufacture, []() { return Computer::cpuManufacture(); }}, - {StructureToken::ComputerCPUType, []() { return Computer::cpuType(); }}, - {StructureToken::ComputerCPUModel, []() { return Computer::cpuModel(); }}, - {StructureToken::ComputerGPUManufacture, []() { return Computer::gpuManufacture(); }}, - {StructureToken::ComputerGPUType, []() { return Computer::gpuType(); }}, - {StructureToken::ComputerGPUModel, []() { return Computer::gpuModel(); }}, - - {StructureToken::CryptoSHA256, []() { return Crypto::sha256(); }}, - {StructureToken::CryptoMD5, []() { return Crypto::md5(); }}, - - {StructureToken::DatabaseColumnName, []() { return Database::columnName(); }}, - {StructureToken::DatabaseColumnType, []() { return Database::columnType(); }}, - {StructureToken::DatabaseCollation, []() { return Database::collation(); }}, - {StructureToken::DatabaseEngine, []() { return Database::engine(); }}, - {StructureToken::DatabaseMongoDBObjectId, []() { return Database::mongoDbObjectId(); }}, - - {StructureToken::DatatypeBoolean, []() { return std::to_string(Datatype::boolean()); }}, - - {StructureToken::DatePastDateISO, []() { return Date::pastDate(); }}, - {StructureToken::DatePastDateTimestamp, []() { return Date::pastDate(1, Date::DateFormat::Timestamp); }}, - {StructureToken::DatefutureDateISO, []() { return Date::futureDate(); }}, - {StructureToken::DatefutureDateTimestamp, []() { return Date::futureDate(1, Date::DateFormat::Timestamp); }}, - {StructureToken::DateRecentDateISO, []() { return Date::recentDate(); }}, - {StructureToken::DateRecentDateTimestamp, []() { return Date::recentDate(3, Date::DateFormat::Timestamp); }}, - {StructureToken::DateSoonDateISO, []() { return Date::soonDate(); }}, - {StructureToken::DateSoonDateTimestamp, []() { return Date::soonDate(3, Date::DateFormat::Timestamp); }}, - {StructureToken::DateBirthdateByAgeISO, []() { return Date::birthdateByAge(); }}, - {StructureToken::DateBirthdateByYearTimestamp, - []() { return Date::birthdateByYear(1920, 2000, Date::DateFormat::Timestamp); }}, - {StructureToken::DateWeekdayName, []() { return Date::weekdayName(); }}, - {StructureToken::DateWeekdayAbbreviatedName, []() { return Date::weekdayAbbreviatedName(); }}, - {StructureToken::DateMontName, []() { return Date::monthName(); }}, - {StructureToken::DateMonthAbbreviatedName, []() { return Date::monthAbbreviatedName(); }}, - - {StructureToken::FinanceCurrencyName, []() { return Finance::currencyName(); }}, - {StructureToken::FinanceCurrencyCode, []() { return Finance::currencyCode(); }}, - {StructureToken::FinanceCurrencySymbol, []() { return Finance::currencySymbol(); }}, - {StructureToken::FinanceAccountType, []() { return Finance::accountType(); }}, - {StructureToken::FinanceAmount, []() { return Finance::amount(); }}, - {StructureToken::FinanceIban, []() { return Finance::iban(); }}, - {StructureToken::FinanceBic, []() { return Finance::bic(); }}, - {StructureToken::FinanceAccountNumber, []() { return Finance::accountNumber(); }}, - {StructureToken::FinancePin, []() { return Finance::pin(); }}, - {StructureToken::FinanceRoutingNumber, []() { return Finance::routingNumber(); }}, - {StructureToken::FinanceCreditCardNumber, []() { return Finance::creditCardNumber(); }}, - {StructureToken::FinanceCreditCardCvv, []() { return Finance::creditCardCvv(); }}, - {StructureToken::FinanceBitcoinAddress, []() { return Finance::bitcoinAddress(); }}, - {StructureToken::FinanceLitecoinAddress, []() { return Finance::litecoinAddress(); }}, - {StructureToken::FinanceEthereumAddress, []() { return Finance::ethereumAddress(); }}, - - {StructureToken::FoodAlcoholicBeverage, []() { return Food::alcoholicBeverage(); }}, - {StructureToken::FoodGrain, []() { return Food::grain(); }}, - {StructureToken::FoodMilkProduct, []() { return Food::milkProduct(); }}, - {StructureToken::FoodFruit, []() { return Food::fruit(); }}, - {StructureToken::FoodMeat, []() { return Food::meat(); }}, - {StructureToken::FoodSeafood, []() { return Food::seafood(); }}, - {StructureToken::FoodVegetable, []() { return Food::vegetable(); }}, - {StructureToken::FoodOil, []() { return Food::oil(); }}, - {StructureToken::FoodNut, []() { return Food::nut(); }}, - {StructureToken::FoodSeed, []() { return Food::seed(); }}, - {StructureToken::FoodSugarProduct, []() { return Food::sugarProduct(); }}, - {StructureToken::FoodNonAlcoholicBeverage, []() { return Food::nonalcoholicBeverage(); }}, - {StructureToken::FoodDishName, []() { return Food::dishName(); }}, - {StructureToken::FoodFoodCategory, []() { return Food::foodCategory(); }}, - - {StructureToken::GitBranch, []() { return Git::branch(); }}, - {StructureToken::GitCommitDate, []() { return Git::commitDate(); }}, - {StructureToken::GitCommitEntry, []() { return Git::commitEntry(); }}, - {StructureToken::GitCommitMessage, []() { return Git::commitMessage(); }}, - {StructureToken::GitCommitSha, []() { return Git::commitSha(); }}, - - {StructureToken::HackerAbbreviation, []() { return Hacker::abbreviation(); }}, - {StructureToken::HackerAdjective, []() { return Hacker::adjective(); }}, - {StructureToken::HackerNoun, []() { return Hacker::noun(); }}, - {StructureToken::HackerVerb, []() { return Hacker::verb(); }}, - {StructureToken::HackerIngverb, []() { return Hacker::ingverb(); }}, - {StructureToken::HackerPhrase, []() { return Hacker::phrase(); }}, - - {StructureToken::ImageImageURL, []() { return Image::imageUrl(); }}, - {StructureToken::ImageGitHubAvatarURL, []() { return Image::githubAvatarUrl(); }}, - {StructureToken::ImageDimensions, []() { return Image::dimensions(); }}, - - {StructureToken::InternetUsername, []() { return Internet::username(); }}, - {StructureToken::InternetEmail, []() { return Internet::email(); }}, - {StructureToken::InternetExampleEmail, []() { return Internet::exampleEmail(); }}, - {StructureToken::InternetPassword, []() { return Internet::password(); }}, - {StructureToken::InternetEmoji, []() { return Internet::emoji(); }}, - {StructureToken::InternetProtocol, []() { return Internet::protocol(); }}, - {StructureToken::InternetHttpMethod, []() { return Internet::httpMethod(); }}, - {StructureToken::InternetHttpRequestHeader, []() { return Internet::httpRequestHeader(); }}, - {StructureToken::InternetHttpResponseHeader, []() { return Internet::httpResponseHeader(); }}, - {StructureToken::InternetHttpMediaType, []() { return Internet::httpMediaType(); }}, - {StructureToken::InternetIpv4, []() { return Internet::ipv4(); }}, - {StructureToken::InternetIpv6, []() { return Internet::ipv6(); }}, - {StructureToken::InternetMac, []() { return Internet::mac(); }}, - {StructureToken::InternetURL, []() { return Internet::url(); }}, - {StructureToken::InternetDomainName, []() { return Internet::domainName(); }}, - {StructureToken::InternetDomainWord, []() { return Internet::domainWord(); }}, - {StructureToken::InternetDomainSuffix, []() { return Internet::domainSuffix(); }}, - - {StructureToken::LocationCountry, []() { return Location::country(); }}, - {StructureToken::LocationCountryCode, []() { return Location::countryCode(); }}, - {StructureToken::LocationState, []() { return Location::state(); }}, - {StructureToken::LocationCity, []() { return Location::city(); }}, - {StructureToken::LocationZipCode, []() { return Location::zipCode(); }}, - {StructureToken::LocationStreetAddress, []() { return Location::streetAddress(); }}, - {StructureToken::LocationStreet, []() { return Location::street(); }}, - {StructureToken::LocationBuildingNumber, []() { return Location::buildingNumber(); }}, - {StructureToken::LocationSecondaryAddress, []() { return Location::secondaryAddress(); }}, - {StructureToken::LocationLatitude, []() { return Location::latitude(); }}, - {StructureToken::LocationLongitude, []() { return Location::longitude(); }}, - {StructureToken::LocationDirection, []() { return Location::direction(); }}, - {StructureToken::LocationTimeZone, []() { return Location::timeZone(); }}, - - // Lorem module - {StructureToken::LoremWord, []() { return Lorem::word(); }}, - {StructureToken::LoremWords, []() { return Lorem::words(); }}, - {StructureToken::LoremSentence, []() { return Lorem::sentence(); }}, - {StructureToken::LoremSentences, []() { return Lorem::sentences(); }}, - {StructureToken::LoremSlung, []() { return Lorem::slug(10); }}, - {StructureToken::LoremParagraph, []() { return Lorem::paragraph(); }}, - {StructureToken::LoremParagraphs, []() { return Lorem::paragraphs(); }}, - - // Medicine module - {StructureToken::MedicineCondition, []() { return Medicine::condition(); }}, - {StructureToken::MedicineMedicalTest, []() { return Medicine::medicalTest(); }}, - {StructureToken::MedicineSpecialty, []() { return Medicine::specialty(); }}, - - // Movie module - {StructureToken::MovieGenre, []() { return Movie::genre(); }}, - {StructureToken::MovieMovieTitle, []() { return Movie::movieTitle(); }}, - {StructureToken::MovieTvShow, []() { return Movie::tvShow(); }}, - {StructureToken::MovieDirector, []() { return Movie::director(); }}, - {StructureToken::MovieActor, []() { return Movie::actor(); }}, - {StructureToken::MovieActress, []() { return Movie::actress(); }}, - - // Music module - {StructureToken::MusicArtist, []() { return Music::artist(); }}, - {StructureToken::MusicGenre, []() { return Music::genre(); }}, - {StructureToken::MusicSongName, []() { return Music::songName(); }}, - - // Person module - {StructureToken::PersonFirstName, []() { return Person::firstName(); }}, - {StructureToken::PersonLastName, []() { return Person::lastName(); }}, - {StructureToken::PersonMiddleName, []() { return Person::middleName(); }}, - {StructureToken::PersonFullName, []() { return Person::fullName(); }}, - {StructureToken::PersonPrefix, []() { return Person::prefix(); }}, - {StructureToken::PersonSuffix, []() { return Person::suffix(); }}, - {StructureToken::PersonSex, []() { return Person::sex(); }}, - {StructureToken::PersonGender, []() { return Person::gender(); }}, - {StructureToken::PersonJobTitle, []() { return Person::jobTitle(); }}, - {StructureToken::PersonJobDescriptor, []() { return Person::jobDescriptor(); }}, - {StructureToken::PersonJobArea, []() { return Person::jobArea(); }}, - {StructureToken::PersonJobType, []() { return Person::jobType(); }}, - {StructureToken::PersonHoby, []() { return Person::hobby(); }}, - {StructureToken::PersonLanguage, []() { return Person::language(); }}, - {StructureToken::PersonNationality, []() { return Person::nationality(); }}, - {StructureToken::PersonWesternZodiac, []() { return Person::westernZodiac(); }}, - {StructureToken::PersonChineseZodiac, []() { return Person::chineseZodiac(); }}, - - // Phone module - {StructureToken::PhoneNumber, []() { return Phone::number(); }}, - {StructureToken::PhonePlatform, []() { return Phone::platform(); }}, - {StructureToken::PhoneModelName, []() { return Phone::modelName(); }}, - {StructureToken::PhoneManufacturer, []() { return Phone::manufacturer(); }}, - {StructureToken::PhoneIMEI, []() { return Phone::imei(); }}, - - // Sport module - {StructureToken::SportSport, []() { return Sport::sport(); }}, - {StructureToken::SportSoccerTeam, []() { return Sport::soccerTeam(); }}, - {StructureToken::SportMaleAthelete, []() { return Sport::maleAthlete(); }}, - {StructureToken::SportFemaleAthlete, []() { return Sport::femaleAthlete(); }}, - {StructureToken::SportSportEvent, []() { return Sport::sportEvent(); }}, - - // System module - {StructureToken::SystemFileName, []() { return System::fileName(); }}, - {StructureToken::SystemFileExtension, []() { return System::fileExtension(); }}, - {StructureToken::SystemCommonFileName, []() { return System::commonFileName(); }}, - {StructureToken::SystemCommonFileExtension, []() { return System::commonFileExtension(); }}, - {StructureToken::SystemMimeType, []() { return System::mimeType(); }}, - {StructureToken::SystemCommonFileType, []() { return System::commonFileType(); }}, - {StructureToken::SystemFileType, []() { return System::fileType(); }}, - {StructureToken::SystemDirectoryPath, []() { return System::directoryPath(); }}, - {StructureToken::SystemFilePath, []() { return System::filePath(); }}, - {StructureToken::SystemSemver, []() { return System::semver(); }}, - {StructureToken::SystemNetworkInterface, []() { return System::networkInterface(); }}, - {StructureToken::SystemCron, []() { return System::cron(); }}, - - // VideoGame module - {StructureToken::VideoGameGameTitle, []() { return VideoGame::gameTitle(); }}, - {StructureToken::VideoGameGenre, []() { return VideoGame::genre(); }}, - {StructureToken::VideoGamePlatform, []() { return VideoGame::platform(); }}, - {StructureToken::VideoGameStudioName, []() { return VideoGame::studioName(); }}, - - // Weather module - {StructureToken::WeatherTemperatureMetric, []() { return std::to_string(Weather::temperature().metric); }}, - - {StructureToken::WeatherTemperatureImperial, []() { return std::to_string(Weather::temperature().imperial); }}, - {StructureToken::WeatherPressureMetric, []() { return std::to_string(Weather::pressure().metric); }}, - {StructureToken::WeatherPressureImperial, []() { return std::to_string(Weather::pressure().imperial); }}, - {StructureToken::WeatherVisibilityMetric, []() { return std::to_string(Weather::visibility().metric); }}, - {StructureToken::WeatherVisibilityImperial, []() { return std::to_string(Weather::visibility().imperial); }}, - {StructureToken::WeatherWindSpeedMetric, []() { return std::to_string(Weather::windSpeed().metric); }}, - {StructureToken::WeatherWindSpeedImperial, []() { return std::to_string(Weather::windSpeed().imperial); }}, - {StructureToken::WeatherUvIndex, []() { return std::to_string(Weather::uvIndex()); }}, - {StructureToken::WeatherHumidity, []() { return std::to_string(Weather::humidity()); }}, - {StructureToken::WeatherWeatherDescription, []() { return Weather::weatherDescription(); }}, - {StructureToken::WeatherCloudCover, []() { return std::to_string(Weather::cloudCover()); }}, - - // Word module - {StructureToken::WordSample, []() { return Word::sample(); }}, - {StructureToken::WordWords, []() { return Word::words(); }}, - {StructureToken::WordAdjective, []() { return Word::adjective(); }}, - {StructureToken::WordAdverb, []() { return Word::adverb(); }}, - {StructureToken::WordConjunction, []() { return Word::conjunction(); }}, - {StructureToken::WordInterjection, []() { return Word::interjection(); }}, - {StructureToken::WordNoun, []() { return Word::noun(); }}, - {StructureToken::WordPreposition, []() { return Word::preposition(); }}, - {StructureToken::WordVerb, []() { return Word::verb(); }}, -}; - -std::string Structure::json(const std::map& items) -{ - std::string result = "{"; - - for (auto it = items.begin(); it != items.end(); ++it) - { - auto func = moduleFunctions.find(it->second)->second; - - result.append("\"" + it->first + "\":\"" + func() + "\""); - - if (std::next(it) != items.end()) - { - result.append(","); - } - } - - result.append("}"); - - return result; -} - -std::string Structure::csv(const std::map& items, const unsigned int rows) -{ - std::string result; - - std::vector> funcs; - - for (auto it = items.begin(); it != items.end(); ++it) - { - result.append(it->first); - - funcs.push_back(moduleFunctions.find(it->second)->second); - - if (std::next(it) != items.end()) - { - result.append(","); - } - } - - result.append("\n"); - - std::size_t n = funcs.size(); - - for (size_t i = 0; i < rows; i++) - { - for (size_t j = 0; j < n; ++j) - { - result.append(funcs[j]()); - - if (j != n - 1) - { - result.append(","); - } - } - - result.append("\n"); - } - - return result; -} -} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3c461d7fb..9589ad4be 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -44,7 +44,6 @@ set(FAKER_UT_SOURCES modules/science/ScienceTest.cpp modules/sport/SportTest.cpp modules/string/StringTest.cpp - modules/structure/StructureTest.cpp modules/system/SystemTest.cpp modules/vehicle/VehicleTest.cpp modules/videoGame/VideoGameTest.cpp @@ -55,7 +54,7 @@ set(FAKER_UT_SOURCES add_executable(${PROJECT_NAME} ${FAKER_UT_SOURCES}) if (MSVC) target_compile_options(${PROJECT_NAME} PRIVATE /permissive- /bigobj) -endif() +endif () target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/common @@ -68,7 +67,7 @@ if (USE_SYSTEM_DEPENDENCIES) GTest::gtest_main GTest::gmock GTest::gmock_main faker-cxx) else () add_subdirectory("${CMAKE_SOURCE_DIR}/externals/googletest" - "${CMAKE_BINARY_DIR}/googletest") + "${CMAKE_BINARY_DIR}/googletest") set(GTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/googletest/googletest/include") diff --git a/tests/modules/structure/StructureTest.cpp b/tests/modules/structure/StructureTest.cpp deleted file mode 100644 index 4e1e73ccd..000000000 --- a/tests/modules/structure/StructureTest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -#include "faker-cxx/Structure.h" - -#include -#include - -#include "gtest/gtest.h" - -#include "common/StringHelper.h" -#include "airline/data/Airports.h" -#include "animal/data/Birds.h" -#include "book/data/Titles.h" -#include "movie/data/Actors.h" - -using namespace faker; -using namespace ::testing; - -class StructureTest : public Test -{ -public: - static std::map parseJson(const std::string& json) - { - std::map result; - std::istringstream stream(json); - std::string key, value, temp; - char ch; - - while (stream >> ch && ch != '}') - { - if (ch == '"') - { - - std::getline(stream, key, '"'); - std::getline(stream, temp, ':'); - - stream >> ch; - std::getline(stream, value, '"'); - - result[key] = value; - } - } - - return result; - } -}; - -TEST_F(StructureTest, shouldGenerateJson) -{ - std::map testTokens; - testTokens.emplace("Airport name", StructureToken::AirlineAirportName); - testTokens.emplace("Bird name", StructureToken::AnimalBird); - testTokens.emplace("Book title", StructureToken::BookTitle); - testTokens.emplace("Actor name", StructureToken::MovieActor); - const auto generatedJson = Structure::json(testTokens); - - const auto parsedJson = parseJson(generatedJson); - - const auto key1 = parsedJson.find("Airport name")->first; - const auto key2 = parsedJson.find("Bird name")->first; - const auto key3 = parsedJson.find("Book title")->first; - const auto key4 = parsedJson.find("Actor name")->first; - - const auto value1 = parsedJson.find("Airport name")->second; - const auto value2 = parsedJson.find("Bird name")->second; - const auto value3 = parsedJson.find("Book title")->second; - const auto value4 = parsedJson.find("Actor name")->second; - - ASSERT_EQ(key1, "Airport name"); - ASSERT_EQ(key2, "Bird name"); - ASSERT_EQ(key3, "Book title"); - ASSERT_EQ(key4, "Actor name"); - - ASSERT_TRUE( - std::ranges::any_of(airports, [value1](const Airline::Airport& airport) { return airport.name == value1; })); - ASSERT_TRUE(std::ranges::any_of(birds, [value2](const std::string& bird) { return bird == value2; })); - ASSERT_TRUE(std::ranges::any_of(titles, [value3](const std::string& title) { return title == value3; })); - ASSERT_TRUE(std::ranges::any_of(actors, [value4](const std::string& actor) { return actor == value4; })); -} - -TEST_F(StructureTest, shouldGenerateCSV) -{ - std::map testTokens; - const unsigned int noRows = 2; - testTokens.emplace("Airport name", StructureToken::AirlineAirportName); - testTokens.emplace("Bird name", StructureToken::AnimalBird); - testTokens.emplace("Book title", StructureToken::BookTitle); - testTokens.emplace("Actor name", StructureToken::MovieActor); - - const auto generatedCSV = Structure::csv(testTokens, noRows); - - std::istringstream dataStream(generatedCSV); - std::string line; - - std::getline(dataStream, line); - std::vector keys = StringHelper::split(line, ","); - - ASSERT_EQ(keys.at(0), "Actor name"); - ASSERT_EQ(keys.at(1), "Airport name"); - ASSERT_EQ(keys.at(2), "Bird name"); - ASSERT_EQ(keys.at(3), "Book title"); - - while (std::getline(dataStream, line)) - { - ASSERT_TRUE(std::ranges::any_of(actors, [&line](const std::string& actor) - { return line.find(actor) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(airports, [&line](const Airline::Airport& airport) - { return line.find(airport.name) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(birds, [&line](const std::string& bird) - { return line.find(bird) != std::string::npos; })); - ASSERT_TRUE(std::ranges::any_of(titles, [&line](const std::string& title) - { return line.find(title) != std::string::npos; })); - } -}