1 // Written in the D programming language.
2 
3 /**
4  * Functions related to binary build and binary/binding versioning and unittests.
5  */
6 
7 module wrapper.sodium.version_;
8 
9 import wrapper.sodium.core; // assure sodium got initialized
10 
11 public
12 import  deimos.sodium.version_ : SODIUM_VERSION_STRING,
13                                  SODIUM_LIBRARY_VERSION_MAJOR,
14                                  SODIUM_LIBRARY_VERSION_MINOR,
15 //                               sodium_version_string,
16                                  sodium_library_version_major,
17                                  sodium_library_version_minor,
18                                  sodium_library_minimal;
19 
20 /* Wrapper(s)/substitute(s) for 'deimos' functions */
21 
22 /// Returns: The sodium binary public version string as D string
23 pragma(inline, true)
24 string sodium_version_string() @nogc nothrow pure @trusted
25 {
26     import std..string : fromStringz;
27     static import deimos.sodium.version_;
28 
29     return fromStringz(deimos.sodium.version_.sodium_version_string());
30 }
31 
32 /* unittest(s) : They cover all deimos/wrapper functions and their attributes, use all enums */
33 
34 @nogc nothrow pure @safe unittest
35 {
36     static import deimos.sodium.version_;
37 
38     assert(deimos.sodium.version_.sodium_version_string() == sodium_version_string().ptr,
39            "sodium_version_string() implementation error");
40     cast(void) deimos.sodium.version_.sodium_version_string();
41     cast(void) sodium_version_string();
42     cast(void) sodium_library_version_major();
43     cast(void) sodium_library_version_minor();
44     cast(void) sodium_library_minimal();
45 }
46 
47 /*@nogc*/
48 nothrow pure @safe unittest
49 {
50     import core.exception : AssertError;
51     import std.stdio : writeln;
52 
53     try
54         debug
55         {
56             writeln("unittest block 1 from sodium.version_.d");
57             writeln("SODIUM_VERSION_STRING        of binding: ", SODIUM_VERSION_STRING);
58             writeln("SODIUM_VERSION_STRING        of binary:  ", sodium_version_string());
59 
60             writeln("SODIUM_LIBRARY_VERSION_MAJOR of binding: ", SODIUM_LIBRARY_VERSION_MAJOR);
61             writeln("SODIUM_LIBRARY_VERSION_MAJOR of binary:  ", sodium_library_version_major());
62 
63             writeln("SODIUM_LIBRARY_VERSION_MINOR of binding: ", SODIUM_LIBRARY_VERSION_MINOR);
64             writeln("SODIUM_LIBRARY_VERSION_MINOR of binary:  ", sodium_library_version_minor());
65 
66             writeln("Whether binary was compiled in minimal mode (#define SODIUM_LIBRARY_MINIMAL): ",
67                     sodium_library_minimal());
68         }
69     catch (Exception e) { throw new AssertError("unittest block 1 from sodium.version_.d", __FILE__, __LINE__); }
70 
71 /*
72   If SODIUM_VERSION_STRING of binding and binary don't match:
73   This is a binding to the C source version stated in README.md.
74   I don't track in this binding, if function signatures etc. did change among different C source versions and which function was introduced in which version!
75   The former is unlikely, thus using the binary with this binding (omitting 'new' functions not supported by the binary in use and omitting a unittest build) should work.
76   The latter, that functions get added from C source version to version and get tested in the wrapper's unittests is much more likely,
77   which will probably result in a linking failure for a unittest build indicating the unresolved symbols:
78   Thus the user has to either update the binary or manually comment out those lines of unittests to get a unittest build.
79   In order to run the latest binary (my package distribution currently offers version 1.0.16 while 1.0.18 is released) I did a manual build using checkinstall
80   instead of 'make install', which integrates nicely as package in the package system (Kubuntu).
81   Based on matching SODIUM_VERSION_STRING of binding and binary the unittests are tested to compile and run successfully with Linux and Windows.
82 */
83 }