Back to index

nux  3.0.0
gtest-nux-emmetrics.cpp
Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <gmock/gmock.h>
00003 
00004 #include "Nux/Nux.h"
00005 #include "Nux/EMMetrics.h"
00006 
00007 namespace {
00008   TEST(TestMetrics, TestCreate)
00009   {
00010     // Test fallback (no display) of constructor, DPI of 96.0 will be used
00011     nux::EMMetrics* metrics5  = new nux::EMMetrics(NULL, 0,  5.0);
00012     nux::EMMetrics* metrics10 = new nux::EMMetrics(NULL, 0, 10.0);
00013     nux::EMMetrics* metrics15 = new nux::EMMetrics(NULL, 0, 15.0);
00014     nux::EMMetrics* metrics20 = new nux::EMMetrics(NULL, 0, 20.0);
00015 
00016     // Test conversion from pixel to EM (testing fallback-case) 5-point font
00017     EXPECT_EQ(metrics5->Pixel2EM(30), 4.5);
00018     EXPECT_EQ(metrics5->Pixel2EM(25), 3.75);
00019     EXPECT_EQ(metrics5->Pixel2EM(20), 3.0);
00020     EXPECT_EQ(metrics5->Pixel2EM(15), 2.25);
00021     EXPECT_EQ(metrics5->Pixel2EM(10), 1.5);
00022     EXPECT_EQ(metrics5->Pixel2EM(5),  0.75);
00023     EXPECT_EQ(metrics5->Pixel2EM(0),  0.0);
00024 
00025     // Test conversion from EM to pixel (testing fallback-case) 5-point font
00026     EXPECT_EQ(metrics5->EM2Pixel(4.5),  30);
00027     EXPECT_EQ(metrics5->EM2Pixel(3.75), 25);
00028     EXPECT_EQ(metrics5->EM2Pixel(3.0),  20);
00029     EXPECT_EQ(metrics5->EM2Pixel(2.25), 15);
00030     EXPECT_EQ(metrics5->EM2Pixel(1.5),  10);
00031     EXPECT_EQ(metrics5->EM2Pixel(0.75),  5);
00032     EXPECT_EQ(metrics5->EM2Pixel(0.0),   0);
00033 
00034     // Test conversion from pixel to EM (testing fallback-case) 10-point font
00035     EXPECT_EQ(metrics10->Pixel2EM(30), 2.25);
00036     EXPECT_EQ(metrics10->Pixel2EM(25), 1.875);
00037     EXPECT_EQ(metrics10->Pixel2EM(20), 1.5);
00038     EXPECT_EQ(metrics10->Pixel2EM(15), 1.125);
00039     EXPECT_EQ(metrics10->Pixel2EM(10), 0.75);
00040     EXPECT_EQ(metrics10->Pixel2EM(5),  0.375);
00041     EXPECT_EQ(metrics10->Pixel2EM(0),  0.0);
00042 
00043     // Test conversion from EM to pixel (testing fallback-case) 10-point font
00044     EXPECT_EQ(metrics10->EM2Pixel(2.25),  30);
00045     EXPECT_EQ(metrics10->EM2Pixel(1.875), 25);
00046     EXPECT_EQ(metrics10->EM2Pixel(1.5),   20);
00047     EXPECT_EQ(metrics10->EM2Pixel(1.125), 15);
00048     EXPECT_EQ(metrics10->EM2Pixel(0.75),  10);
00049     EXPECT_EQ(metrics10->EM2Pixel(0.375),  5);
00050     EXPECT_EQ(metrics10->EM2Pixel(0.0),    0);
00051 
00052     // Test conversion from pixel to EM (testing fallback-case) 15-point font
00053     EXPECT_EQ(metrics15->Pixel2EM(30), 1.5);
00054     EXPECT_EQ(metrics15->Pixel2EM(25), 1.25);
00055     EXPECT_EQ(metrics15->Pixel2EM(20), 1.0);
00056     EXPECT_EQ(metrics15->Pixel2EM(15), 0.75);
00057     EXPECT_EQ(metrics15->Pixel2EM(10), 0.5);
00058     EXPECT_EQ(metrics15->Pixel2EM(5),  0.25);
00059     EXPECT_EQ(metrics15->Pixel2EM(0),  0.0);
00060 
00061     // Test conversion from EM to pixel (testing fallback-case) 15-point font
00062     EXPECT_EQ(metrics15->EM2Pixel(1.5),  30);
00063     EXPECT_EQ(metrics15->EM2Pixel(1.25), 25);
00064     EXPECT_EQ(metrics15->EM2Pixel(1.0),  20);
00065     EXPECT_EQ(metrics15->EM2Pixel(0.75), 15);
00066     EXPECT_EQ(metrics15->EM2Pixel(0.5),  10);
00067     EXPECT_EQ(metrics15->EM2Pixel(0.25),  5);
00068     EXPECT_EQ(metrics15->EM2Pixel(0.0),   0);
00069 
00070     // Test conversion from pixel to EM (testing fallback-case) 20-point font
00071     EXPECT_EQ(metrics20->Pixel2EM(30), 1.125);
00072     EXPECT_EQ(metrics20->Pixel2EM(25), 0.9375);
00073     EXPECT_EQ(metrics20->Pixel2EM(20), 0.75);
00074     EXPECT_EQ(metrics20->Pixel2EM(15), 0.5625);
00075     EXPECT_EQ(metrics20->Pixel2EM(10), 0.375);
00076     EXPECT_EQ(metrics20->Pixel2EM(5),  0.1875);
00077     EXPECT_EQ(metrics20->Pixel2EM(0),  0.0);
00078 
00079     // Test conversion from EM to pixel (testing fallback-case) 20-point font
00080     EXPECT_EQ(metrics20->EM2Pixel(1.125),  30);
00081     EXPECT_EQ(metrics20->EM2Pixel(0.9375), 25);
00082     EXPECT_EQ(metrics20->EM2Pixel(0.75),   20);
00083     EXPECT_EQ(metrics20->EM2Pixel(0.5625), 15);
00084     EXPECT_EQ(metrics20->EM2Pixel(0.375),  10);
00085     EXPECT_EQ(metrics20->EM2Pixel(0.1875),  5);
00086     EXPECT_EQ(metrics20->EM2Pixel(0.0),     0);
00087 
00088     delete metrics5;
00089     delete metrics10;
00090     delete metrics15;
00091     delete metrics20;
00092   }
00093 } // unnamed namespace
00094