diff --git a/include/faker-cxx/Image.h b/include/faker-cxx/Image.h index a9617f755..21dd3f555 100644 --- a/include/faker-cxx/Image.h +++ b/include/faker-cxx/Image.h @@ -21,9 +21,9 @@ class Image * @returns Random real image url from external service. * * @code - * Internet::imageUrl() // "https://loremflickr.com/640/480" - * Internet::imageUrl(800, 600) // "https://loremflickr.com/800/600" - * Internet::imageUrl(800, 600, ImageCategory::animals) // "https://loremflickr.com/800/600/animals" + * Image::imageUrl() // "https://loremflickr.com/640/480" + * Image::imageUrl(800, 600) // "https://loremflickr.com/800/600" + * Image::imageUrl(800, 600, ImageCategory::Animals) // "https://loremflickr.com/800/600/animals" * @endcode */ static std::string imageUrl(unsigned width = 640, unsigned height = 480, @@ -35,7 +35,7 @@ class Image * @returns Url to github avatar. * * @code - * Internet::githubAvatarUrl() // "https://avatars.githubusercontent.com/u/9716558" + * Image::githubAvatarUrl() // "https://avatars.githubusercontent.com/u/9716558" * @endcode */ static std::string githubAvatarUrl(); @@ -46,9 +46,19 @@ class Image * @returns Random image dimensions. * * @code - * Internet::dimensions() // "1920x1080" + * Image::dimensions() // "1920x1080" * @endcode */ static std::string dimensions(); + + /** + * @brief Generates a random type of image. + * + * @returns Type of image. + * + * @code + * Image::type() // "png" + */ + static std::string type(); }; } diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index bd5e0f6ec..691b63d4b 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -1,6 +1,8 @@ #include "faker-cxx/Image.h" #include "../../common/FormatHelper.h" +#include "data/Type.h" +#include "faker-cxx/Helper.h" #include "faker-cxx/Number.h" namespace faker @@ -37,4 +39,8 @@ std::string Image::dimensions() return FormatHelper::format("{}x{}", Number::integer(1, 32720), Number::integer(1, 17280)); } +std::string Image::type() +{ + return Helper::arrayElement(imageTypes); +} } diff --git a/src/modules/image/ImageTest.cpp b/src/modules/image/ImageTest.cpp index 86bf9bf6e..ae4eb975a 100644 --- a/src/modules/image/ImageTest.cpp +++ b/src/modules/image/ImageTest.cpp @@ -1,10 +1,12 @@ #include "faker-cxx/Image.h" #include +#include #include "gtest/gtest.h" #include "../src/common/StringHelper.h" +#include "data/Type.h" using namespace ::testing; using namespace faker; @@ -66,3 +68,11 @@ TEST_F(ImageTest, shouldGenerateDimensions) auto height_dimension = std::stoi(split_dimensions[1]); ASSERT_TRUE(height_dimension >= 1 && height_dimension <= 17280); } + +TEST_F(ImageTest, shouldGenerateType) +{ + const auto generatedType = Image::type(); + + ASSERT_TRUE(std::ranges::any_of(imageTypes, [generatedType](const std::string& type) + { return type == generatedType; })); +} \ No newline at end of file diff --git a/src/modules/image/data/Type.h b/src/modules/image/data/Type.h new file mode 100644 index 000000000..c9dd7f444 --- /dev/null +++ b/src/modules/image/data/Type.h @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +namespace faker +{ +const std::vector imageTypes = {"ai", "bmp", "eps", "gif", "heif", "indd", "jpeg", "jpg", + "pdf", "png", "psd", "raw", "svg", "tiff", "webp"}; +} \ No newline at end of file