canvas_test.cpp 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Canvas unit tests
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <colour.h>
  10. #include <canvas.h>
  11. #include <math.h>
  12. #include <gtest/gtest.h>
  13. TEST(CanvasTest, Creating_a_canvas)
  14. {
  15. Canvas c = Canvas(10, 20);
  16. int x, y;
  17. ASSERT_EQ(c.width, 10);
  18. ASSERT_EQ(c.height, 20);
  19. for(y = 0; y < 20; y++)
  20. {
  21. for(x = 0; x < 10; x++)
  22. {
  23. ASSERT_EQ(c.getPixel(x, y), Colour(0, 0, 0));
  24. }
  25. }
  26. }
  27. TEST(CanvasTest, Test_Writing_pixels_to_a_canvas_Test)
  28. {
  29. Canvas c = Canvas(10, 20);
  30. Colour red = Colour(1, 0, 0);
  31. c.putPixel(2, 3, red);
  32. ASSERT_EQ(c.getPixel(2, 3), red);
  33. }
  34. TEST(CanvasTest, Save_a_PNG_file)
  35. {
  36. Canvas c = Canvas(5, 3);
  37. Colour c1 = Colour(1.5, 0, 0);
  38. Colour c2 = Colour(0, 0.5, 0);
  39. Colour c3 = Colour(-0.5, 0, 1);
  40. c.putPixel(0, 0, c1);
  41. c.putPixel(2, 1, c2);
  42. c.putPixel(4, 2, c3);
  43. ASSERT_TRUE(c.SaveAsPNG("Save_a_PNG_file.png"));
  44. }