Anonymous avatar Anonymous committed 288d674

Added a test for the grand library.

Comments (0)

Files changed (4)

rand-seed-serve/libseedserve/Makefile

 	gcc -L./.libs -o $@ main-run.o -l$(NAME)
 	
 $(LIBNAME): $(NAME).o
-	libtool --mode=link gcc -shared $(CFLAGS) -o $@ -version-info 0:0:0 $<
+	libtool --mode=link gcc -shared $(CFLAGS) -o $@.0 -version-info 0:0:0 $<
+	if ! test -e $@ ; then ln -s $@.0 $@ ; fi
 
 $(GRAND_LIBNAME): grand.o $(LIBNAME) 
-	libtool --mode=link gcc -shared $(CFLAGS) -o $@ -version-info 0:0:0 $< -l$(NAME)
+	libtool --mode=link gcc -shared $(CFLAGS) -o $@.0 -version-info 0:0:0 $< -l$(NAME)
+	mv .libs/$@.0 .
+	if ! test -e $@ ; then ln -s $@.0 $@ ; fi
+
+grand-test-good: grand-test-good.c
+	gcc -o $@ `pkg-config glib-2.0 --cflags` $< `pkg-config glib-2.0 --libs`
+
+grand-test-experiment: grand-test-experiment.c
+	gcc -o $@ `pkg-config glib-2.0 --cflags` $< `pkg-config glib-2.0 --libs`
+
+grand-test-output.good.txt: grand-test-good
+	./$< > $@
 
 TEST_VERBOSE = 0
 
-test: $(TARGETS)
-	PERL_DL_NONLAZY=1 perl "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE))" test-seedserve.t
+test: $(TARGETS) grand-test-output.good.txt grand-test-experiment
+	PERL_DL_NONLAZY=1 perl "-MExtUtils::Command::MM" "-e" "test_harness($(TEST_VERBOSE))" test-seedserve.t test-grand.t
 
 

rand-seed-serve/libseedserve/grand-test-experiment.c

+#include <glib.h>
+
+int main()
+{
+    GRand * gr;
+    int i;
+
+    gr = g_rand_new();
+
+    for(i=0;i<100;i++)
+    {
+        printf("%i\n", g_rand_int(gr));
+    }
+    
+    g_rand_free(gr);
+
+    return 0;
+}

rand-seed-serve/libseedserve/grand-test-good.c

+#include <glib.h>
+
+int main()
+{
+    GRand * gr;
+    int i;
+
+    gr = g_rand_new_with_seed(24);
+
+    for(i=0;i<100;i++)
+    {
+        printf("%i\n", g_rand_int(gr));
+    }
+    
+    g_rand_free(gr);
+
+    return 0;
+}

rand-seed-serve/libseedserve/test-grand.t

+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+# change 'tests => 1' to 'tests => last_test_to_print';
+
+use Test::More tests => 1;
+
+use IO::All;
+use Cwd;
+
+use Net::SeedServe::Server;
+
+# First of all - start the service.
+my $server =
+    Net::SeedServe::Server->new(
+        'status_file' => "temp/server-status.txt",
+    );
+
+my $ret = $server->start();
+my $port = $ret->{'port'};
+
+$ENV{'SEEDSERVE_PORT'} = $port;
+
+$ENV{'LD_PRELOAD'} = getcwd()."/libgrand_seedserve.so";
+
+# The eval { } is to trap exceptions, so we can safely stop the server at 
+# cleanup.
+eval {
+    $server->clear();
+    $server->enqueue([24]);
+    
+    my $result = `./grand-test-experiment`;
+    my $expected = io()->file("grand-test-output.good.txt")->slurp();
+    # TEST
+    is ($result, $expected, "Comparing Output of Seed Serve");
+};
+
+$server->stop();
+
+if ($@)
+{
+    die $@;
+}
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.