Debian Codegraph @

test/bar_codes_test.adb

raw
1 with Ada.Characters.Handling,
2 Ada.Numerics.Float_Random,
3 Ada.Streams.Stream_IO;
4
5 with Bar_Codes, Bar_Codes_Media;
6
7 procedure Bar_Codes_Test is
8
9 procedure Spit (kind : Bar_Codes.Kind_Of_Code; file_name_part, text : String) is
10 use Bar_Codes, Bar_Codes_Media;
11 use Ada.Characters.Handling, Ada.Streams.Stream_IO;
12 png : File_Type;
13 prefix : constant String := "test " & To_Lower (kind'Image) & ' ';
14 begin
15 if file_name_part = "" then
16 Create (png, Out_File, prefix & text & ".png");
17 else
18 Create (png, Out_File, prefix & file_name_part & ".png");
19 end if;
20 if Code_2D_Square (kind) then
21 -- Square 2D codes need square modules.
22 PNG_Bar_Code (kind, 2, 2, text, Stream (png).all);
23 else
24 case kind is
25 when Code_1D =>
26 -- 1D modules are as high as you wish.
27 PNG_Bar_Code (kind, 2, 30, text, Stream (png).all);
28 when Code_DM_Rectangular =>
29 PNG_Bar_Code (kind, 2, 2, text, Stream (png).all);
30 when others =>
31 pragma Assert (Code_2D_Square (kind));
32 end case;
33 end if;
34 Close (png);
35 end Spit;
36
37 procedure Test_128 is
38 use Bar_Codes;
39 use Ada.Numerics.Float_Random;
40 chunks : constant := 2;
41 c : Character := ASCII.DEL;
42 msg : String (1 .. 128 / chunks);
43 rnd : String (1 .. 50);
44 gen : Generator;
45 n : Positive;
46 begin
47 for chunk in 1 .. chunks loop
48 for i in msg'Range loop
49 msg (i) := c;
50 if c > ASCII.NUL then
51 c := Character'Pred (c);
52 end if;
53 end loop;
54 Spit (Code_128, chunk'Image, msg);
55 end loop;
56 Spit (Code_128, "vn1", "0520");
57 Spit (Code_128, "vn2", "993512176004535560");
58 Spit (Code_128, "", "12345abc1234abc1234567a123bcdef12345");
59 Reset (gen, 1);
60 for iter in 1 .. 9 loop
61 for i in rnd'Range loop
62 rnd (i) := Character'Val (32 + Integer (Random (gen) * 95.0));
63 end loop;
64 -- Put a few non-printable characters...
65 for i in rnd'Range loop
66 if Random (gen) < 0.1 then
67 rnd (i) := ASCII.ESC;
68 end if;
69 end loop;
70 -- Put a few sequences of digits...
71 for i in rnd'Range loop
72 if Random (gen) < 0.08 then
73 n := 1 + Integer (Random (gen) * 6.0);
74 for j in i .. Integer'Min (rnd'Last, i + n) loop
75 rnd (j) := Character'Val (Character'Pos ('0') + Integer (Random (gen) * 9.0));
76 end loop;
77 end if;
78 end loop;
79 Spit (Code_128, "rnd" & iter'Image, rnd);
80 -- Digits only (must be all with subcode C):
81 for i in rnd'Range loop
82 rnd (i) := Character'Val (Character'Pos ('0') + Integer (Random (gen) * 9.0));
83 end loop;
84 Spit (Code_128, "rnd digits" & iter'Image, rnd);
85 end loop;
86 end Test_128;
87
88 procedure Test_MSI is
89 begin
90 Spit (Bar_Codes.Code_MSI, "", "1234567890");
91 Spit (Bar_Codes.Code_MSI, "", "1234576890");
92 Spit (Bar_Codes.Code_MSI, "", "12345678901");
93 Spit (Bar_Codes.Code_MSI, "", "998877665544332211");
94 Spit (Bar_Codes.Code_MSI, "", "97531");
95 Spit (Bar_Codes.Code_MSI, "", "24680");
96 end Test_MSI;
97
98 procedure Test_EAN13 is
99 begin
100 for initial_digit in Character range '0' .. '9' loop
101 Spit (Bar_Codes.Code_EAN13, (1 => initial_digit), initial_digit & "12345678901");
102 end loop;
103 end Test_EAN13;
104
105 procedure Test_UPCA is
106 begin
107 Spit (Bar_Codes.Code_UPCA, "", "12345678901");
108 end Test_UPCA;
109
110 procedure Test_2D is
111 blabla : constant String :=
112 "The Corporate Bullshit Generator " &
113 " *** " &
114 "Short URL (for bookmark and sharing): http://cbsg.sf.net " &
115 " *** " &
116 "A pre-integrated, non-deterministic and high-performance intellect " &
117 "deepens mobility spaces. " &
118 "Offshorings expediently generate our world-class and fast-paced brand image. " &
119 "A segmentation influences the decision makers, while multi-divisional, " &
120 "service-oriented, pipelines quickly streamline evolutions. " &
121 "Above-average next steps incentivise the initiator; nevertheless " &
122 "the enablers orchestrate the adjustments. A continual increase in " &
123 "margins goes hand-in-hand with a measured gain in task efficiency." &
124 " *** " &
125 "The project Ada Bar Codes provides a package for generating " &
126 "various types of bar codes on different output formats," &
127 "such as PDF, SVG or bitmaps." &
128 " *** " &
129 "Zip-Ada is a programming library for dealing with the Zip compressed " &
130 "archive file format. The full sources of Zip-Ada are in Ada, " &
131 "compilable on every compiler and for every system. For more details, " &
132 "read the files zipada.txt and zip.ads from the archive below." &
133 " *** " &
134 "GLOBE_3D stands for GL Object Based Engine for 3D." &
135 "GL stands for Graphics Library, created by SGI. " &
136 "SGI stands for Silicon Graphics, Inc. " &
137 "Short description: GLOBE_3D is a free, open-source," &
138 "real-time 3D Engine written in Ada, based on OpenGL.";
139 begin
140 for c in Bar_Codes.Code_2D loop
141 Spit (c, "blabla 0001", blabla (1 .. 0001));
142 Spit (c, "blabla 0010", blabla (1 .. 0010));
143 Spit (c, "blabla 0035", blabla (1 .. 0035));
144 Spit (c, "blabla 0100", blabla (1 .. 0100));
145 Spit (c, "blabla 0250", blabla (1 .. 0250));
146 Spit (c, "blabla 0500", blabla (1 .. 0500));
147 Spit (c, "blabla full", blabla);
148 end loop;
149 end Test_2D;
150 begin
151 Test_128;
152 Test_MSI;
153 Test_EAN13;
154 Test_UPCA;
155 Test_2D;
156 end Bar_Codes_Test;