Browse Source

[RWPNM] Testing

master
Unbewohnte 3 years ago
parent
commit
9f598d4159
  1. 8
      .gitignore
  2. 21
      build/CMakeLists.txt
  3. 33
      src/pnm.cpp
  4. 8
      tests/Makefile
  5. 29
      tests/test.cpp

8
.gitignore vendored

@ -1,6 +1,2 @@
/build/CMakeFiles
/build/cmake_install.cmake
/build/Makefile
/build/CMakeCache.txt
/bin
image.ppm
image.ppm
test

21
build/CMakeLists.txt

@ -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})

33
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<iostream>
#include<vector>
#include<fstream>
#ifndef RWPNM
#define RWPNM
#include <vector>
#include <fstream>
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

8
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

29
tests/test.cpp

@ -0,0 +1,29 @@
#include <iostream>
#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;
}
Loading…
Cancel
Save