Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
test_user.cpp File Reference
#include "user.hpp"
#include <doctest.h>
#include <iostream>
#include <sstream>

Go to the source code of this file.

Functions

 TEST_CASE ("User constructor initializes fields")
 
 TEST_CASE ("User::print() outputs correct format")
 
 TEST_CASE ("fetch_github_user returns valid user for known GitHub account")
 
 TEST_CASE ("fetch_github_user throws for nonexistent username")
 

Function Documentation

◆ TEST_CASE() [1/4]

TEST_CASE ( "fetch_github_user returns valid user for known GitHub account" )

Definition at line 36 of file test_user.cpp.

36 {
37 User user = User::fetch_github_user("octocat");
38
39 CHECK(user.login == "octocat");
40
41 // These fields can change, so we check they are not empty instead
42 CHECK_FALSE(user.name.empty());
43 CHECK_FALSE(user.company.empty());
44 CHECK_FALSE(user.location.empty());
45}
#define CHECK_FALSE(...)
Definition doctest.h:2971
#define CHECK(...)
Definition doctest.h:2970
Structure representing a GitHub user.
Definition user.h:9
const char * name
Full name.
Definition user.h:11
const char * login
GitHub username.
Definition user.h:10
const char * location
User's location.
Definition user.h:13
const char * company
Company name.
Definition user.h:12

References CHECK, CHECK_FALSE, User::company, User::location, User::login, and User::name.

◆ TEST_CASE() [2/4]

TEST_CASE ( "fetch_github_user throws for nonexistent username" )

Definition at line 47 of file test_user.cpp.

47 {
48 std::string invalid_username = "this_user_should_not_exist_123456789";
49
50 CHECK_THROWS_AS(User::fetch_github_user(invalid_username),
51 std::runtime_error);
52}
#define CHECK_THROWS_AS(expr,...)
Definition doctest.h:2973

References CHECK_THROWS_AS.

◆ TEST_CASE() [3/4]

TEST_CASE ( "User constructor initializes fields" )

Definition at line 8 of file test_user.cpp.

8 {
9 User user("octocat", "The Octocat", "GitHub", "San Francisco");
10
11 CHECK(user.login == "octocat");
12 CHECK(user.name == "The Octocat");
13 CHECK(user.company == "GitHub");
14 CHECK(user.location == "San Francisco");
15}

References CHECK, User::company, User::location, User::login, and User::name.

◆ TEST_CASE() [4/4]

TEST_CASE ( "User::print() outputs correct format" )

Definition at line 17 of file test_user.cpp.

17 {
18 User user("octocat", "The Octocat", "GitHub", "San Francisco");
19
20 std::ostringstream output;
21 std::streambuf *old_cout_buf = std::cout.rdbuf(output.rdbuf());
22
23 user.print();
24
25 std::cout.rdbuf(old_cout_buf); // restore std::cout
26
27 std::string result = output.str();
28 CHECK(result.find("Login: octocat") != std::string::npos);
29 CHECK(result.find("Name: The Octocat") != std::string::npos);
30 CHECK(result.find("Company: GitHub") != std::string::npos);
31 CHECK(result.find("Location: San Francisco") != std::string::npos);
32}
static const char * output

References CHECK, and output.