DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testColor.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "ConfigTest.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/Color.h"

Go to the source code of this file.

Functions

bool testColor ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2014/11/16

Functions for testing class Color.

This file is part of the DGtal library.

Definition in file testColor.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 140 of file testColor.cpp.

141{
142 trace.beginBlock ( "Testing class Color" );
143 trace.info() << "Args:";
144 for ( int i = 0; i < argc; ++i )
145 trace.info() << " " << argv[ i ];
146 trace.info() << endl;
147
148 bool res = testColor(); // && ... other tests
149 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
150 trace.endBlock();
151 return res ? 0 : 1;
152}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testColor()
Definition: testColor.cpp:48

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testColor(), and DGtal::trace.

◆ testColor()

bool testColor ( )

Example of a test. To be completed.

Definition at line 48 of file testColor.cpp.

49{
50 unsigned int nbok = 0;
51 unsigned int nb = 0;
52
53 trace.beginBlock ( "Testing Color ..." );
54
55 Color b(0,0,0,255);
56 Color g(32,32,32,255);
57 Color gg(64,64,64,255);
58 Color w(255,255,255,255);
59
60 trace.info() << " B+G = g "<< b+g<<std::endl;
61 nbok += ((b+g)==g) ? 1 : 0;
62 nb++;
63 trace.info() << "(" << nbok << "/" << nb << ") "
64 << "add" << std::endl;
65
66 trace.info() << " g+g = gg "<< g*2<< " expected ="<<gg<<std::endl;
67 nbok += ((g+g)==gg) ? 1 : 0;
68 nb++;
69 trace.info() << "(" << nbok << "/" << nb << ") "
70 << "add (bis)" << std::endl;
71
72 trace.info() << " W+W = w "<< w+w<<std::endl;
73 nbok += ((w+w)==w) ? 1 : 0;
74 nb++;
75 trace.info() << "(" << nbok << "/" << nb << ") "
76 << "max " << std::endl;
77
78 trace.info() << " g*2 = gg "<< g*2<< " expected ="<<gg<<std::endl;
79 nbok += ((g*2)==gg) ? 1 : 0;
80 nb++;
81 trace.info() << "(" << nbok << "/" << nb << ") "
82 << "coeff" << std::endl;
83
84 trace.info() << " 1.*red = red "<< 1.0*Color::Red<< " expected ="<<Color::Red<<std::endl;
85 nbok += ((1.0*Color::Red)==Color::Red) ? 1 : 0;
86 nb++;
87 trace.info() << "(" << nbok << "/" << nb << ") "
88 << "coeff" << std::endl;
89
90 trace.info() << " 2*g = gg "<< 2.0*g<< " expected ="<<gg<<std::endl;
91 nbok += ((2*g)==gg) ? 1 : 0;
92 nb++;
93 trace.info() << "(" << nbok << "/" << nb << ") "
94 << "coeff" << std::endl;
95
96 //Checking alpha channel
97 Color a(0,0,0,64);
98 Color aa(0,0,0,32);
99 Color c = a+aa;
100#ifdef COLOR_WITH_ALPHA_ARITH
101 trace.info() << " a+aa = "<< a+aa<<std::endl;
102 nbok += (c == Color(0,0,0,96)) ? 1 : 0;
103 nb++;
104 trace.info() << "(" << nbok << "/" << nb << ") "
105 << "alpha arith (enabled)" << std::endl;
106#else
107 trace.info() << " a+aa = "<< a+aa<<std::endl;
108 nbok += (c == Color(0,0,0,64)) ? 1 : 0;
109 nb++;
110 trace.info() << "(" << nbok << "/" << nb << ") "
111 << "alpha arith (disabled)" << std::endl;
112#endif
113
114 Color val;
115 val.setRGBi(0,0,0,255);
116 val += 1.0*Color::Red;
117 trace.info() << " val == Color::Red "<< val<<std::endl;
118 nbok += (val==Color::Red) ? 1 : 0;
119 nb++;
120
121 trace.info() << "(" << nbok << "/" << nb << ") "
122 << "red" << std::endl;
123
124 // Test Color is trivialy_copiable
125 const auto is_trivially_copyable_ = std::is_trivially_copyable<Color>::value;
126 trace.info() << "is_trivially_copyable: "<< is_trivially_copyable_ <<std::endl;
127 nbok += (is_trivially_copyable_) ? 1 : 0;
128 nb++;
129 trace.info() << "(" << nbok << "/" << nb << ") "
130 << "is_trivially_copyable" << std::endl;
131
132 trace.endBlock();
133
134 return nbok == nb;
135}
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
Color & setRGBi(const unsigned char aRedValue, const unsigned char aGreenValue, const unsigned char aBlueValue, const unsigned char aAlphaValue=255)
static const Color Red
Definition: Color.h:416

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::Color::Red, DGtal::Color::setRGBi(), and DGtal::trace.

Referenced by main().