Skip to content

Commit

Permalink
remove some of api types to corresponding modules (#276)
Browse files Browse the repository at this point in the history
* remove some of api types to corresponding modules

* remove some of api types to corresponding modules v2
  • Loading branch information
cieslarmichal authored Nov 18, 2023
1 parent fa16152 commit 699eb15
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 85 deletions.
12 changes: 9 additions & 3 deletions include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <string>

#include "types/EmojiType.h"
#include "types/Ipv4Address.h"
#include "types/Ipv4Class.h"

namespace faker
{
Expand All @@ -24,6 +22,13 @@ enum class WebProtocol
Https
};

enum class IPv4Class
{
A,
B,
C
};

class Internet
{
public:
Expand Down Expand Up @@ -210,7 +215,8 @@ class Internet
* Internet::ipv4({255.255.128.0}, {129.168.255.0}) // "192.168.128.10"
* @endcode
*/
static std::string ipv4(const IPv4Address& baseIpv4Address, const IPv4Address& generationMask);
static std::string ipv4(const std::array<unsigned int, 4>& baseIpv4Address,
const std::array<unsigned int, 4>& generationMask);

/**
* @brief Returns a string containing randomized ipv6 address.
Expand Down
29 changes: 25 additions & 4 deletions include/faker-cxx/System.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
#pragma once

#include "types/CronOptions.h"
#include "types/FileOptions.h"
#include <optional>

#include "types/FileType.h"
#include "types/MimeTypes.h"
#include "types/NetworkInterfaceOptions.h"

namespace faker
{
struct FileOptions
{
int extensionCount = 1;
struct
{
int min = 1;
int max = 1;
} extensionRange;
};

struct CronOptions
{
bool includeYear = false;
bool includeNonStandard = false;
};

// TODO: change to enums
struct NetworkInterfaceOptions
{
std::optional<std::string> interfaceType;
std::optional<std::string> interfaceSchema;
};

class System
{
public:
Expand Down
13 changes: 0 additions & 13 deletions include/faker-cxx/types/CronOptions.h

This file was deleted.

14 changes: 0 additions & 14 deletions include/faker-cxx/types/FileOptions.h

This file was deleted.

8 changes: 0 additions & 8 deletions include/faker-cxx/types/Ipv4Address.h

This file was deleted.

11 changes: 0 additions & 11 deletions include/faker-cxx/types/Ipv4Class.h

This file was deleted.

10 changes: 0 additions & 10 deletions include/faker-cxx/types/MimeTypes.h

This file was deleted.

15 changes: 0 additions & 15 deletions include/faker-cxx/types/NetworkInterfaceOptions.h

This file was deleted.

7 changes: 4 additions & 3 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ std::string Internet::httpMediaType()

std::string Internet::ipv4(IPv4Class ipv4class)
{
IPv4Address sectors;
std::array<unsigned int, 4> sectors{};

sectors[3] = Number::integer<unsigned int>(ipv4SectorUpperBound);
sectors[2] = Number::integer<unsigned int>(ipv4SectorUpperBound);
Expand Down Expand Up @@ -208,9 +208,10 @@ std::string Internet::ipv4(IPv4Class ipv4class)
return fmt::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]);
}

std::string Internet::ipv4(const IPv4Address& baseIpv4Address, const IPv4Address& generationMask)
std::string Internet::ipv4(const std::array<unsigned int, 4>& baseIpv4Address,
const std::array<unsigned int, 4>& generationMask)
{
IPv4Address sectors;
std::array<unsigned int, 4> sectors{};

for (std::size_t i = 0; i < ipv4AddressSectors; i++)
{
Expand Down
8 changes: 4 additions & 4 deletions src/modules/internet/InternetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ constexpr unsigned int classBSecondSectionUpperBound = 31;
constexpr unsigned int classCFirstSection = 192u;
constexpr unsigned int classCSecondSection = 168u;

IPv4Address deconstructIpv4String(const std::string& ipv4)
std::array<unsigned int, 4> deconstructIpv4String(const std::string& ipv4)
{
IPv4Address result;
std::array<unsigned int, 4> result;

std::istringstream ss(ipv4);

Expand Down Expand Up @@ -604,8 +604,8 @@ TEST_F(InternetTest, shouldGenerateIpv4WithPrivateClassCAddress)

TEST_F(InternetTest, shouldGenerateIpv4KeepingTheMaskedPart)
{
const IPv4Address sampleAddress = {192, 168, 10, 12};
const IPv4Address generationMask = {255, 128, 0, 0};
const std::array<unsigned int, 4> sampleAddress = {192, 168, 10, 12};
const std::array<unsigned int, 4> generationMask = {255, 128, 0, 0};

const auto generatedAddress = deconstructIpv4String(Internet::ipv4(sampleAddress, generationMask));

Expand Down

0 comments on commit 699eb15

Please sign in to comment.