Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
cmake_minimum_required(VERSION 3.10)
project(GenLeetcodeQuestion)

# Specify vcpkg toolchain
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
# Enable C++11 standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Specify vcpkg toolchain (only if on Windows with vcpkg)
if(EXISTS "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(CMAKE_TOOLCHAIN_FILE "C:/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()

find_package(nlohmann_json CONFIG REQUIRED)
find_package(CURL REQUIRED)

set(CURL_INCLUDE_DIR "C:/vcpkg/installed/x64-windows/include")
set(CURL_LIBRARY "C:/vcpkg/installed/x64-windows/lib/libcurl.a")
set(CMAKE_BUILD_TYPE Debug)
add_executable(main main.cpp)
# Set build type if not specified
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()

target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)
# Create a library with the utility functions
add_library(utils utils.cpp)
target_link_libraries(utils PUBLIC nlohmann_json::nlohmann_json)

# Main executable
add_executable(main main.cpp)
target_link_libraries(main PRIVATE utils nlohmann_json::nlohmann_json CURL::libcurl)

target_link_libraries(main PRIVATE CURL::libcurl)
# Test executable (optional, requires Google Test)
option(BUILD_TESTS "Build the tests" ON)
if(BUILD_TESTS)
# Try to find Google Test
find_package(GTest QUIET)

if(GTest_FOUND)
enable_testing()

add_executable(test_main test_main.cpp)
target_link_libraries(test_main PRIVATE utils GTest::gtest GTest::gtest_main)

# Add test to CTest
add_test(NAME UtilsTests COMMAND test_main)

message(STATUS "Tests enabled - run 'ctest' or './test_main' to execute tests")
else()
message(WARNING "Google Test not found. Tests will not be built. Install with: sudo apt-get install libgtest-dev (Linux) or vcpkg install gtest (Windows)")
endif()
endif()
78 changes: 78 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Testing Guide

## Overview

This project includes a comprehensive test suite using Google Test (gtest) to verify the functionality of the utility functions.

## Test Coverage

The test suite includes 22 tests across 3 test suites:

### FormatHTMLToStringTest (11 tests)
- HTML tag removal (simple and nested)
- HTML entity conversion (<, >, &, 's,  )
- Whitespace handling (newlines and tabs)
- Edge cases (empty strings, complex HTML)

### GetTestCasesTest (5 tests)
- Single and multiple test case parsing
- Empty content handling
- Content without examples
- Single and multiple parameter parsing

### GetParamNameTest (6 tests)
- Parameter name and value extraction
- Various formatting (with/without spaces)
- Complex array parameters
- String parameters

## Building and Running Tests

### Prerequisites

```bash
sudo apt-get install libgtest-dev libcurl4-openssl-dev nlohmann-json3-dev cmake g++
```

### Build

```bash
mkdir -p build
cd build
cmake ..
make
```

### Run Tests

There are two ways to run the tests:

1. **Direct execution:**
```bash
cd build
./test_main
```

2. **Using CTest:**
```bash
cd build
ctest --verbose
```

## Test Results

All 22 tests currently pass:
- ✅ 11/11 FormatHTMLToStringTest
- ✅ 5/5 GetTestCasesTest
- ✅ 6/6 GetParamNameTest

## Code Structure

- `test_main.cpp` - Test implementation using Google Test framework
- `utils.h` - Header file with function declarations
- `utils.cpp` - Implementation of utility functions
- `main.cpp` - Main application (uses the utilities)

## Bug Fixes

During test development, we identified and fixed boundary check issues in `FormatHTMLToString()` where HTML entities at the end of strings were not being processed correctly.
184 changes: 0 additions & 184 deletions build/ALL_BUILD.vcxproj

This file was deleted.

8 changes: 0 additions & 8 deletions build/ALL_BUILD.vcxproj.filters

This file was deleted.

Loading