Correct code and enable tests for ETL "spline" and "value"
[synfig.git] / ETL / test / value.cpp
1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
3 ** Generic Value Test
4 ** $Id$
5 **
6 ** Copyright (c) 2002 Adrian Bentley
7 **
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
12 **
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 ** General Public License for more details.
17 **
18 ** === N O T E S ===========================================================
19 **
20 ** ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #include <ETL/value>
25 #include <stdio.h>
26
27 /* === M A C R O S ========================================================= */
28
29 using namespace etl;
30
31 /* === C L A S S E S ======================================================= */
32
33 /* === P R O C E D U R E S ================================================= */
34
35 /* === E N T R Y P O I N T ================================================= */
36
37 struct stupidv
38 {
39         float x,y;
40
41         stupidv(float xin=0, float yin=0) :x(xin),y(yin) {}
42         void print() const
43         {
44                 printf("(x=%f,y=%f)\n",x,y);
45         }
46 };
47
48 struct stupidp
49 {
50         float z,w;
51
52         stupidp(float zin=0, float win=0) :z(zin),w(win) {}
53
54         void print() const
55         {
56                 printf("(z=%f,w=%f)\n",z,w);
57         }
58 };
59
60 #if 0
61 template <>
62 class etl::value_store_type<stupidp>
63 {
64         typedef stupidv value_type;
65 };
66 #endif
67
68 int main()
69 {
70         try
71         {
72         value   v(10.0); //construction
73         value   v2;              //default construct...
74
75         //get type...
76         printf("type of 10.0: %s\n", v.type().name());
77
78         v2 = 1; //assignment
79         printf("type of 1: %s\n", v2.type().name());
80
81         //extract int test
82
83         int *pi = value_cast<int>(&v2);
84         printf("v2 is an int(%p)\n", pi);
85         printf("        %d\n", value_cast<int>(v2));
86
87         printf("        const version: %d\n", value_cast<int>(value(5)));
88
89         v = 'c'; //assignment again...
90         printf("type of c: %s\n", v.type().name());
91
92         v2 = v; //value assignment
93         printf("type of v2 , v: %s , %s\n", v2.type().name(), v.type().name());
94
95         //random type test
96         v = stupidv(0,1);
97         printf("type of vec: %s\n", v.type().name());
98
99         //type cast with binary change test
100         value_cast<stupidp>(&v)->print();
101         value_cast<stupidv>(stupidp(5,10)).print(); //copy test
102
103         printf("type of v: %s\n", v.type().name());
104         printf("type of v2: %s\n", v2.type().name());
105         v.swap(v2);
106         printf("type of v: %s\n", v.type().name());
107         printf("type of v2: %s\n", v2.type().name());
108
109         // test the exception throwing...
110         value_cast<int>(stupidp(6,66));
111
112         }catch(const etl::bad_value_cast &e)
113         {
114                 printf("        Exploded: %s\n",e.what());
115         }catch(...)
116         {
117                 printf("        Exploded\n");
118         }
119
120         return 0;
121 }