-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add initial examples Signed-off-by: Uilian Ries <[email protected]> * Fix examples description Signed-off-by: Uilian Ries <[email protected]> * Fix linker name Signed-off-by: Uilian Ries <[email protected]> --------- Signed-off-by: Uilian Ries <[email protected]>
- Loading branch information
1 parent
339d899
commit 64b5612
Showing
9 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(faker-cxx-examples LANGUAGES CXX) | ||
|
||
add_subdirectory(basic) | ||
add_subdirectory(person) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Faker-cxx Examples | ||
|
||
This repository contains examples for using the Faker-cxx library. | ||
|
||
## Building with CMake | ||
|
||
To build the examples, you should follow the [CONTRIBUTING.md](../CONTRIBUTING.md) guide as usual, | ||
however you should pass `-DBUILD_EXAMPLE=ON` to CMake in order to build examples. It's disabled | ||
by default. For instance: | ||
|
||
```sh | ||
cmake -S . --preset <preset-name> -DBUILD_EXAMPLES=ON | ||
``` | ||
|
||
## Running examples | ||
|
||
In order to run a built example application, you need to go to the build folder, then run the application: | ||
|
||
``` | ||
cd build/<preset-name>/examples/person | ||
./faker-cxx-person-example | ||
``` | ||
|
||
However, using CMake, you can execute all examples individually: | ||
|
||
``` | ||
cmake --build --preset <preset-name> --target run-faker-cxx-person-example | ||
``` | ||
|
||
The custom CMake target `run-faker-cxx-person-example` will run the faker-cxx-person-example. | ||
Only needs to add the prefix `run-` to the example name. | ||
|
||
## Examples: | ||
|
||
Here is a list of availables examples in this folder. | ||
|
||
### Basic | ||
|
||
It follows the main example listed in the [README.md](../README.md) root file. | ||
|
||
### Person | ||
|
||
The `Person` example demonstrates how to generate fake person data using the Faker-cxx library. It showcases various features and functions provided by the library to generate realistic person information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(faker-cxx-basic-example LANGUAGES CXX) | ||
|
||
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) | ||
target_link_libraries(${PROJECT_NAME} faker-cxx) | ||
|
||
add_custom_target(run-${PROJECT_NAME} | ||
DEPENDS ${PROJECT_NAME} | ||
COMMAND ${PROJECT_NAME} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
COMMENT "Running ${PROJECT_NAME}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "faker-cxx/Date.h" | ||
#include "faker-cxx/Internet.h" | ||
#include "faker-cxx/Location.h" | ||
#include "faker-cxx/String.h" | ||
|
||
int main() | ||
{ | ||
const auto id = faker::String::uuid(); | ||
const auto email = faker::Internet::email(); | ||
const auto password = faker::Internet::password(); | ||
const auto city = faker::Location::city(); | ||
const auto streetAddress = faker::Location::streetAddress(); | ||
|
||
std::cout << id << std::endl; | ||
std::cout << email << std::endl; | ||
std::cout << password << std::endl; | ||
std::cout << city << std::endl; | ||
std::cout << streetAddress << std::endl; | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
cmake_minimum_required(VERSION 3.22) | ||
project(faker-cxx-person-example LANGUAGES CXX) | ||
|
||
add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) | ||
target_link_libraries(${PROJECT_NAME} faker-cxx) | ||
|
||
add_custom_target(run-${PROJECT_NAME} | ||
DEPENDS ${PROJECT_NAME} | ||
COMMAND ${PROJECT_NAME} | ||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | ||
COMMENT "Running ${PROJECT_NAME}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <cstdlib> | ||
#include <iostream> | ||
|
||
#include "faker-cxx/Person.h" | ||
|
||
int main() { | ||
const auto personFullName = faker::Person::fullName(); | ||
std::cout << "Person full name: " << personFullName << std::endl; | ||
|
||
const auto jobTitle = faker::Person::jobTitle(); | ||
std::cout << "Person job title: " << jobTitle << std::endl; | ||
|
||
const auto hobby = faker::Person::hobby(); | ||
std::cout << "Person hobby: " << hobby << std::endl; | ||
|
||
const auto language = faker::Person::language(); | ||
std::cout << "Person language: " << language << std::endl; | ||
|
||
const auto nationality = faker::Person::nationality(); | ||
std::cout << "Person nationality: " << nationality << std::endl; | ||
|
||
const auto chineseZodiac = faker::Person::chineseZodiac(); | ||
std::cout << "Person chinese zodiac: " << chineseZodiac << std::endl; | ||
|
||
const auto passport = faker::Person::passport(); | ||
std::cout << "Person passport: " << passport << std::endl; | ||
|
||
return EXIT_SUCCESS; | ||
} |