/[gr2lib]/trunk/gr2lib_UnitTest/Program.cs
ViewVC logotype

Annotation of /trunk/gr2lib_UnitTest/Program.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 86 - (hide annotations) (download)
Fri Jul 16 23:35:21 2010 UTC (9 years, 6 months ago) by william
File size: 11574 byte(s)
Add Try/Catch blocks in to all API Calls

1 william 9 using System;
2     using System.Collections.Generic;
3     using System.Text;
4    
5 william 16 using gr2lib.core;
6 william 70 //using gr2lib.core.coretypes;
7 william 16 using gr2lib.core.apiversion;
8 william 50 using gr2lib.core.exceptions;
9 william 69 using gr2lib.core.helpers;
10 william 70 using gr2lib.core.coretypes.implementation;
11 william 86 using System.Runtime.CompilerServices;
12 william 16
13 william 9 namespace gr2lib_UnitTest
14     {
15 william 77
16 william 9 class Program
17     {
18     static void Main(string[] args)
19 william 77 {
20 william 65 string GrannyFilename = shared.GRANNY_TEST_FILE;
21 william 50 try
22     {
23 william 70 #region Check Granny2 API Version
24 william 50 // Setup access to check loaded Granny2 API Version
25 william 58 granny2apiversion apiversion = new granny2apiversion(shared.EXPECTED_API_VERSION);
26 william 16
27 william 50 // Check if the Loaded API Version Matches
28     if (!apiversion.apiversionsmatch)
29     {
30     // the loaded version does not match
31     Console.WriteLine("Warning:\n" +
32     "\t Loaded Granny2 DLL Version: " + apiversion.apiversion.version + "\n" +
33     "\t Expected Version: " + apiversion.expectedapiversion.version);
34     // return from void to exit application
35     return;
36     }
37     else
38     {
39     // the loaded version matches
40     Console.WriteLine("Loaded granny2.dll: " + apiversion.apiversion.version);
41     }
42 william 70 #endregion
43    
44     #region Parse Commandline
45 william 69 if (args.Length == 1)
46 william 65 {
47 william 69 GrannyFilename = args[0];
48 william 65 }
49 william 69 else if (args.Length > 1)
50     {
51 william 77 throw new InvalidOperationException("ERROR: Recieved Invalid Commandline: " + new arraytostring<string, string[]>(args));
52 william 69 }
53 william 61
54 william 65 if (System.IO.File.Exists(GrannyFilename))
55     {
56     Console.WriteLine("Using Granny2 File: " + GrannyFilename);
57     }
58     else
59     {
60     throw new System.IO.FileNotFoundException("Unable to find: " + GrannyFilename);
61     }
62 william 70 #endregion
63 william 61
64 william 74 #region Read Granny2 Data
65 william 86
66 william 70 grnfileinfo info = grnfileinfo.ReadFromFile(GrannyFilename);
67    
68 william 72 #region Read FromFileName
69     Console.WriteLine();
70 william 83 Console.WriteLine("From File Name: " + info.FromFileName);
71     Console.WriteLine("ExtendedData: " + info.ExtendedData);
72 william 72 #endregion
73    
74 william 71 #region Read ArtToolInfo
75 william 70 Console.WriteLine();
76     Console.WriteLine("Art Tool Data:");
77     Console.WriteLine("\tTool Name: " + info.ArtToolInfo.FromArtToolName);
78     Console.WriteLine("\tTool Version: " + string.Format("{0}.{1}", info.ArtToolInfo.ArtToolMajorRevision, info.ArtToolInfo.ArtToolMinorRevision));
79     Console.WriteLine("\tTool Units Per Meter: " + info.ArtToolInfo.UnitsPerMeter);
80    
81 william 83 Console.WriteLine("\tTool Origin: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Origin.x, info.ArtToolInfo.Origin.y, info.ArtToolInfo.Origin.z));
82     Console.WriteLine("\tTool Right: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Right.x, info.ArtToolInfo.Right.y, info.ArtToolInfo.Right.z));
83     Console.WriteLine("\tTool Up: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Up.x, info.ArtToolInfo.Up.y, info.ArtToolInfo.Up.z));
84     Console.WriteLine("\tTool Back: " + string.Format("[{0},{1},{2}]", info.ArtToolInfo.Back.x, info.ArtToolInfo.Back.y, info.ArtToolInfo.Back.z));
85 william 70
86     Console.WriteLine("\tTool ExtendedData: " + info.ArtToolInfo.ExtendedData);
87 william 71 #endregion
88    
89     #region Read ExporterInfo
90     Console.WriteLine();
91     Console.WriteLine("Exporter Info:");
92     Console.WriteLine("\tExporter Name: " + info.ExporterInfo.ExporterName);
93    
94 william 77 Console.WriteLine("\tExporter Version: " +
95     string.Format("{0}.{1}.{2}.{3}",
96 william 71 info.ExporterInfo.ExporterMajorRevision,
97     info.ExporterInfo.ExporterMinorRevision,
98     info.ExporterInfo.ExporterCustomization,
99     info.ExporterInfo.ExporterBuildNumber));
100    
101     Console.WriteLine("\tExporter ExtendedData: " + info.ExporterInfo.ExtendedData);
102     #endregion
103 william 72
104     #region Read Textures
105     Console.WriteLine();
106     Console.WriteLine("Texture List:");
107     foreach (Texture t in info.Textures)
108     {
109     Console.WriteLine("\tName: " + t.FromFileName);
110     Console.WriteLine("\tType: " + t.TextureType);
111     Console.WriteLine("\tWidth: " + t.Width);
112     Console.WriteLine("\tHeight: " + t.Height);
113     Console.WriteLine("\tEncoding: " + t.Encoding);
114     Console.WriteLine("\tSubFormat: " + t.SubFormat);
115     // layout
116     Console.WriteLine("\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
117     Console.WriteLine("\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
118     Console.WriteLine("\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
119     // images
120 william 77 Console.WriteLine("\tImage List:");
121     foreach (Image img in t.Images)
122     {
123     foreach (MIPLevel mip in img.MIPLevels)
124     {
125     Console.WriteLine("\t\tMipLevel Stride: " + mip.Stride);
126     if (mip.Pixels.Count > 0)
127     {
128     Console.WriteLine("\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
129     //// export image
130     //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
131     }
132     }
133     }
134 william 72 Console.WriteLine("\tExtendedData: " + t.ExtendedData);
135     Console.WriteLine();
136     }
137     #endregion
138    
139 william 81 #region Read Materials
140     Console.WriteLine();
141     Console.WriteLine("Material List:");
142     foreach (Material m in info.Materials)
143     {
144     Console.WriteLine("\tMaterial Name: " + m.Name);
145     Console.WriteLine("\t\tMaterial IsTexture: " + m.IsTexture.ToString());
146     if (m.IsTexture)
147     {
148     Texture t = m.Texture;
149     Console.WriteLine("\t\tTexture:");
150     Console.WriteLine("\t\t\tName: " + t.FromFileName);
151     Console.WriteLine("\t\t\tType: " + t.TextureType);
152     Console.WriteLine("\t\t\tWidth: " + t.Width);
153     Console.WriteLine("\t\t\tHeight: " + t.Height);
154     Console.WriteLine("\t\t\tEncoding: " + t.Encoding);
155     Console.WriteLine("\t\t\tSubFormat: " + t.SubFormat);
156     // layout
157     Console.WriteLine("\t\t\tBytes Per Pixel: " + t.Layout.BytesPerPixel);
158     Console.WriteLine("\t\t\tShiftForComponent: " + new arraytostring<int, int[]>(t.Layout.ShiftForComponent));
159     Console.WriteLine("\t\t\tBitsForComponent: " + new arraytostring<int, int[]>(t.Layout.BitsForComponent));
160 william 86
161    
162     Console.WriteLine("\t\t\tImage List:");
163     foreach (Image img in t.Images)
164     {
165     foreach (MIPLevel mip in img.MIPLevels)
166     {
167     Console.WriteLine("\t\t\t\tMipLevel Stride: " + mip.Stride);
168     if (mip.Pixels.Count > 0)
169     {
170     Console.WriteLine("\t\t\t\tMipLevel Pixel: " + "{Pixel Data " + "[" + mip.Pixels.Count + "]}");
171     //// export image
172     //mip.Pixels.Export(@"exported_images\" + t.FromFileName.Name, t.Width, t.Height, mip.Stride);
173     }
174     }
175     }
176    
177 william 81 Console.WriteLine("\t\t\tExtendedData: " + t.ExtendedData);
178     Console.WriteLine();
179     }
180     Console.WriteLine("\t\tExtendedData: " + m.ExtendedData);
181     Console.WriteLine();
182     }
183     #endregion
184 william 83
185    
186     #region Read Skeletons
187     Console.WriteLine();
188     Console.WriteLine("Skeleton List:");
189     foreach (Skeleton s in info.Skeletons)
190     {
191     Console.WriteLine("\tSkeleton Name: " + s.SkeletonName);
192     Console.WriteLine("\tSkeleton LodType: " + s.LodType);
193     Console.WriteLine("\tBones:");
194     foreach (Bone b in s.Bones)
195     {
196     Console.WriteLine("\t\tName: " + b.BoneName);
197     Console.WriteLine("\t\tParent Index: " + b.ParentIndex);
198     Console.WriteLine("\t\tLod Error: " + b.LodError);
199     Console.WriteLine("\t\tTransform: " + b.Transform.ToString());
200     if (b.HasLightInfo) { Console.WriteLine("\t\tLightInfo ExtendedData: " + b.LightInfo.ExtendedData); }
201     if (b.HasCameraInfo) { Console.WriteLine("\t\tCameraInfo ExtendedData: " + b.CameraInfo.ExtendedData); }
202     Console.WriteLine();
203     }
204     Console.WriteLine("\t\tExtendedData: " + s.ExtendedData);
205     Console.WriteLine();
206     }
207     #endregion
208 william 70 }
209     #endregion
210    
211 william 86
212 william 50 catch (granny2apiloadexception ex)
213 william 16 {
214 william 69 Console.WriteLine(ex.Message);
215 william 16 }
216 william 58 catch (Exception ex)
217     {
218 william 86 RuntimeWrappedException rwe = ex as RuntimeWrappedException;
219     if (rwe != null)
220     {
221     Console.WriteLine(rwe.ToString());
222     }
223     else
224     {
225     Console.WriteLine(ex.Message);
226     }
227 william 58 }
228 william 9 }
229     }
230     }
231 william 70

  ViewVC Help
Powered by ViewVC 1.1.22