Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <cstdlib> | ||
2 | #include <fstream> | ||
3 | #include <iostream> | ||
4 | #include <string> | ||
5 | #include <text_conversion_constexpr.h> | ||
6 | |||
7 | namespace | ||
8 | { | ||
9 | /* | ||
10 | * Processes the text of the given intput file. | ||
11 | * | ||
12 | * @param[in] input Path to the input text file to read data from. | ||
13 | * @param[in] output Path to the output text file to write results to. | ||
14 | * @return true if the process succeeded, otherwise false. | ||
15 | */ | ||
16 | 1 | auto process(const char* input, const char* output) | |
17 | { | ||
18 |
5/10✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 times.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 times.
✗ Branch 14 not taken.
|
1 | std::cout << "Input: " << input << "\nOutput: " << output << std::endl; |
19 | |||
20 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::ifstream input_file{input}; |
21 | |||
22 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (!input_file.is_open()) |
23 | { | ||
24 | ✗ | std::cerr << "Failed to open input file:" << input << std::endl; | |
25 | ✗ | return false; | |
26 | } | ||
27 | |||
28 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | std::ofstream output_file{output}; |
29 | |||
30 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (!output_file.is_open()) |
31 | { | ||
32 | ✗ | std::cerr << "Failed to open output file:" << output << std::endl; | |
33 | ✗ | return false; | |
34 | } | ||
35 | |||
36 | 1 | std::string line; | |
37 |
4/6✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 1 times.
|
3 | while (std::getline(input_file, line)) |
38 | { | ||
39 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | text_conversion_constexpr::convert_to_title_case(line); |
40 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | output_file << line << std::endl; |
41 | } | ||
42 | |||
43 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | input_file.close(); |
44 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | output_file.close(); |
45 | |||
46 | 1 | return true; | |
47 | 1 | } | |
48 | } // namespace | ||
49 | |||
50 | 3 | int main(int argc, char* argv[]) | |
51 | { | ||
52 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (argc != 3) |
53 | { | ||
54 | 2 | std::cerr << "Invalid command line arguments. Expected two file paths." << std::endl; | |
55 | 2 | return EXIT_FAILURE; | |
56 | } | ||
57 | |||
58 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (!process(argv[1], argv[2])) |
59 | ✗ | return EXIT_FAILURE; | |
60 | |||
61 | 1 | return EXIT_SUCCESS; | |
62 | } | ||
63 |