Skip to content

Commit 1950409

Browse files
Merge pull request #16 from Kim-SSi/main
Add unit test files - UnitTestData
2 parents 0717e93 + 48ee99a commit 1950409

30 files changed

+167
-0
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Loading
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
// This sample code shows a bug in the .NET marshaller.
2+
// Native C++ functions returning a string (char*) sometimes
3+
// are not marshalled correctly throwing an exception.
4+
// This is the reason why the .NET wrapper converts
5+
// the char-pointer manually into a .NET string.
6+
7+
using System;
8+
using System.Text;
9+
using System.Runtime.InteropServices;
10+
11+
public static class FreeImage
12+
{
13+
private const string dllName = "FreeImage.dll";
14+
15+
[DllImport(dllName, EntryPoint = "FreeImage_GetFormatFromFIF")]
16+
[return: MarshalAs(UnmanagedType.LPStr)]
17+
public static extern string GetFormatFromFIF(int format);
18+
19+
[DllImport(dllName, EntryPoint = "FreeImage_GetFIFExtensionList")]
20+
[return: MarshalAs(UnmanagedType.LPStr)]
21+
public static extern string GetFIFExtensionList(int format);
22+
23+
[DllImport(dllName, EntryPoint = "FreeImage_GetFIFDescription")]
24+
[return: MarshalAs(UnmanagedType.LPStr)]
25+
public static extern string GetFIFDescription(int format);
26+
27+
[DllImport(dllName, EntryPoint = "FreeImage_GetFIFRegExpr")]
28+
[return: MarshalAs(UnmanagedType.LPStr)]
29+
public static extern string GetFIFRegExpr(int format);
30+
31+
[DllImport(dllName, EntryPoint = "FreeImage_GetFIFMimeType")]
32+
[return: MarshalAs(UnmanagedType.LPStr)]
33+
public static extern string GetFIFMimeType(int format);
34+
35+
[DllImport(dllName, EntryPoint = "FreeImage_GetFIFCount")]
36+
public static extern int GetFIFCount();
37+
}
38+
39+
public class Program
40+
{
41+
public static bool[,] getmatrix(int fifCount)
42+
{
43+
bool[,] matrix = new bool[5, fifCount];
44+
45+
int j = 0;
46+
47+
for (int i = 0; i < fifCount; i++)
48+
{
49+
bool success = true;
50+
try
51+
{
52+
FreeImage.GetFormatFromFIF(i);
53+
}
54+
catch
55+
{
56+
success = false;
57+
}
58+
matrix[j, i] = success;
59+
}
60+
j++;
61+
62+
for (int i = 0; i < fifCount; i++)
63+
{
64+
bool success = true;
65+
try
66+
{
67+
FreeImage.GetFIFExtensionList(i);
68+
}
69+
catch
70+
{
71+
success = false;
72+
}
73+
matrix[j, i] = success;
74+
}
75+
j++;
76+
77+
for (int i = 0; i < fifCount; i++)
78+
{
79+
bool success = true;
80+
try
81+
{
82+
FreeImage.GetFIFDescription(i);
83+
}
84+
catch
85+
{
86+
success = false;
87+
}
88+
matrix[j, i] = success;
89+
}
90+
j++;
91+
92+
for (int i = 0; i < fifCount; i++)
93+
{
94+
bool success = true;
95+
try
96+
{
97+
FreeImage.GetFIFRegExpr(i);
98+
}
99+
catch
100+
{
101+
success = false;
102+
}
103+
matrix[j, i] = success;
104+
}
105+
j++;
106+
107+
for (int i = 0; i < fifCount; i++)
108+
{
109+
bool success = true;
110+
try
111+
{
112+
FreeImage.GetFIFMimeType(i);
113+
}
114+
catch
115+
{
116+
success = false;
117+
}
118+
matrix[j, i] = success;
119+
}
120+
121+
return matrix;
122+
}
123+
124+
public static void Main()
125+
{
126+
int fifCount = FreeImage.GetFIFCount();
127+
bool[,] matrix = getmatrix(fifCount);
128+
129+
Console.Clear();
130+
Console.WriteLine("1: GetFormatFromFIF");
131+
Console.WriteLine("2: GetFIFExtensionList");
132+
Console.WriteLine("3: GetFIFDescription");
133+
Console.WriteLine("4: GetFIFRegExpr");
134+
Console.WriteLine("5: GetFIFMimeType");
135+
Console.Write(Environment.NewLine);
136+
137+
Console.Write("FIF:\t");
138+
for (int x = 1; x < 6; x++)
139+
Console.Write("{0}:\t", x);
140+
141+
Console.Write(Environment.NewLine);
142+
143+
for (int k = 0; k < fifCount; k++)
144+
{
145+
Console.Write("{0}:\t", k);
146+
for (int l = 0; l < 5; l++)
147+
{
148+
Console.Write(matrix[l, k] ? "1\t" : "0\t");
149+
}
150+
Console.Write(Environment.NewLine);
151+
}
152+
}
153+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
NUnit 2.x is needed for FreeImage .NET wrapper unit tests. It can be
2+
downloaded from http://www.nunit.org/
3+
4+
After installing NUnit, double click on the NUnit project file
5+
FreeImage.NET.nunit located in the FreeImage .NET wrapper Source folder
6+
to load the project.
7+
8+
The FreeImage .NET wrapper unit test project UnitTest.csproj, located
9+
under Source\UnitTest, must be compiled in 'Debug' mode prior to opening
10+
the NUnit project.
11+
12+
The FreeImage .NET wrapper unit test project UnitTest.csproj currently
13+
relies on the FreeImage .NET wrapper single source file, created by the
14+
Source File Merger, located in the Source\SourceFileMerger folder.

0 commit comments

Comments
 (0)