From 9f598d415931f218114dbade81f70c6a00e49480 Mon Sep 17 00:00:00 2001 From: Unbewohnte Date: Sat, 26 Feb 2022 16:00:43 +0300 Subject: [PATCH] [RWPNM] Testing --- .gitignore | 8 ++------ build/CMakeLists.txt | 21 --------------------- src/pnm.cpp | 33 ++++++++------------------------- tests/Makefile | 8 ++++++++ tests/test.cpp | 29 +++++++++++++++++++++++++++++ 5 files changed, 47 insertions(+), 52 deletions(-) delete mode 100644 build/CMakeLists.txt create mode 100644 tests/Makefile create mode 100644 tests/test.cpp diff --git a/.gitignore b/.gitignore index 0fad2f3..2af2251 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,2 @@ -/build/CMakeFiles -/build/cmake_install.cmake -/build/Makefile -/build/CMakeCache.txt -/bin -image.ppm \ No newline at end of file +image.ppm +test \ No newline at end of file diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt deleted file mode 100644 index 03cc2fa..0000000 --- a/build/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -cmake_minimum_required(VERSION 3.10) - -project(rwpnm) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED True) - -IF(MSVC) - # to be made, probably... -else() - set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") - set(BUILD_SHARED_LIBS OFF) - set(CMAKE_EXE_LINKER_FLAGS "-static") - - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -O2") -endif() - -set(EXECUTABLE_OUTPUT_PATH ../bin) - -FILE(GLOB source_files ../src/*) -add_executable(rwpnm ${source_files}) diff --git a/src/pnm.cpp b/src/pnm.cpp index 0a8208c..a2db39f 100644 --- a/src/pnm.cpp +++ b/src/pnm.cpp @@ -10,10 +10,13 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#include -#include -#include +#ifndef RWPNM +#define RWPNM +#include +#include + +namespace pnm { class Color { public: @@ -98,7 +101,6 @@ public: void save(std::string path) { // check if there are less/more pixels than needed if (m_pixel_data.size() > (m_width * m_height) || m_pixel_data.size() < (m_width * m_height)) { - std::cout << m_pixel_data.size(); throw std::runtime_error("Invalid amount of pixels. There must be width*height pixels"); } @@ -149,29 +151,10 @@ public: if (data.length() == 0) { break; } - std::cout << data; } } }; -int main() { - try { - PPM_writer ppm_image(800, 800); - - uint8_t cc = 0; - for (uint32_t y = 0; y < 800; y++) { - for (uint32_t x = 0; x < 800; x++) { - ppm_image.put_pixel(x, y, RGB(cc, cc, cc)); - - cc++; - } - cc--; - } - ppm_image.save("image.ppm"); - - } catch(const std::exception& e) { - std::cout << "[ERROR] " << e.what() << "\n"; - } - - return 0; } + +#endif \ No newline at end of file diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..0aa0ded --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,8 @@ +test: all + ./test + +all: + g++ test.cpp -Wall -Werror -O2 -static -o test + +clear: + rm -f test image.ppm \ No newline at end of file diff --git a/tests/test.cpp b/tests/test.cpp new file mode 100644 index 0000000..e8409f2 --- /dev/null +++ b/tests/test.cpp @@ -0,0 +1,29 @@ +#include +#include "../src/pnm.cpp" + +using namespace pnm; + +int main() { + try { + PPM_writer ppm_image(800, 800); + + uint8_t cc = 0; + for (uint32_t y = 0; y < 800; y++) { + for (uint32_t x = 0; x < 800; x++) { + ppm_image.put_pixel(x, y, RGB(cc, cc, cc)); + + cc++; + } + cc--; + } + ppm_image.save("image.ppm"); + + } catch(const std::exception& e) { + std::cout << "[ERROR] " << e.what() << "\n"; + return 1; + } + + std::cout << "[SUCCESS]\n"; + + return 0; +}