Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

test cases for testCompat.cxx file

  • Loading branch information...
commit 3013faa14b7a8886df071a418c8bcff32705a0a7 1 parent f250ba5
@shagunshaily authored
Showing with 118 additions and 2 deletions.
  1. +118 −2 rutil/test/testCompat.cxx
View
120 rutil/test/testCompat.cxx
@@ -1,7 +1,7 @@
#include <cassert>
-
+#include<iostream>
#include "rutil/compat.hxx"
-
+#include <cstdio>
using namespace resip;
using namespace std;
@@ -24,6 +24,122 @@ main()
UInt64 data2 = hton64(data);
assert(tmp[7] == 1);
+//test for resipMax
+ {
+ //for postive integer
+ assert(resipMax(3,2) == 3);
+ cerr << "max(3,2 ): " << resipMax(3,2)<<endl;
@dpocock
dpocock added a note

you could also try max(2,3)==3 here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ //for negative integers
+ assert(resipMax(-3,-2) == -2);
+ cerr << "max(-3,-2):" << resipMax(-3,-2)<< endl;
+ //for large integers
+ assert(resipMax(5223372036854775807,9223372036854775807) == 9223372036854775807);
+ cerr<< "max(5223372036854775807,9223372036854775807): "<< resipMax(5223372036854775807,9223372036854775807)<< endl;
@dpocock
dpocock added a note

with these really big values, it may be better to declare them first in variables and then refer to the variables in your test and output code, e.g.
double d1 = 5223.......
double d2 = 922......
assert(resipMax(d1,d2)==d2)
cerr<<"max("<<d1<<","<<d2 .....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ //for large floating point numbers
+ assert(((resipMax(5223372036854775807.9965443,9223372036854775807.1265443) - 9223372036854775807.1265443)/9223372036854775807.1265443) < 0.00000000001) ;
+ cerr<< "max(5223372036854775807.9965443,5223372036854775807.1265443 ): "<< resipMax(5223372036854775807.9965443,9223372036854775807.1265443)<< endl;
+ //for large negative numbers
+ assert(resipMax(-5223372036854775807,-9223372036854775807) == -5223372036854775807);
+ cerr<< "max(-5223372036854775807,9223372036854775807): "<< resipMax(-5223372036854775807,-9223372036854775807)<<endl;
+ //for large negative floating point numbers
+ assert(((resipMax(-5223372036854775807.99,-9223372036854775807.12) - -5223372036854775807.99)/5223372036854775807.99) < 0.00000000001);
+ cerr<< "max(-5223372036854775807.99,-9223372036854775807.12): "<< resipMax(-5223372036854775807.99,-25223372036854775807.12)<< endl;
+ //for same numbers
+ assert(resipMax(3,3) == 3);
+ cerr << "max(3,3 ): " << resipMax(3,3)<<endl;
+ //for char type arguements
+ assert(resipMax('a','b') == 'b');
+ cerr<< "max('a','b'): "<<resipMax('a','b')<<endl;
+ //test for string type arguements
+ assert(resipMax("hello","jello") == "jello");
@dpocock
dpocock added a note

does this actually compare the strings the right way? hint: what happens if you do resipMax("jello", "hello")?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ cerr<<"max('hello','jello'): "<<resipMax("hello","jello")<<endl;
+ }
+ //test for resipMin
+ {
+ //for postive integer
+ assert(resipMin(3,2) == 2);
+ cerr << "min(3,2 ): " << resipMin(3,2)<< endl;
+ //for negative integers
+ assert(resipMin(-3,-2) == -3);
+ cerr << "min(-3,-2): " << resipMin(-3,-2)<< endl;
+ //for large integers
+ assert(resipMin(5223372036854775807,9223372036854775807) == 5223372036854775807);
+ cerr<< "min(5223372036854775807,9223372036854775807): "<< resipMin(5223372036854775807,9223372036854775807)<< endl;
+ //for large floating point numbers
+ assert(((resipMin(5223372036854775807.9965443,9223372036854775807.1265443) - 5223372036854775807.9965443)/5223372036854775807.9965443) < 0.00000000001) ;
+ cerr<< "min(5223372036854775807.9965443,5223372036854775807.1265443 ): "<< resipMin(5223372036854775807.9965443,9223372036854775807.1265443)<< endl;
+ //for large negative numbers
+ assert(resipMin(-5223372036854775807,-9223372036854775807) == -9223372036854775807);
+ cerr<< "min(-5223372036854775807,-9223372036854775807): "<< resipMin(-5223372036854775807,-9223372036854775807)<< endl;
+ //for large negative floating point numbers
+ assert(((resipMin(-5223372036854775807.99,-9223372036854775807.12) - -9223372036854775807.12)/9223372036854775807.12) < 0.0000000000001);
+ cerr<< "min(-5223372036854775807.99,-9223372036854775807.12): "<< resipMin(-5223372036854775807.99,-9223372036854775807.12)<< endl;
+ //for same numbers
+ assert(resipMin(3,3) == 3);
+ cerr << "min(3,3 ): " << resipMin(3,3)<< endl;
+ //for char type arguements
+ assert(resipMin('a','b') == 'a');
+ cerr<< "min('a','b'): "<<resipMin('a','b')<<endl;
+ //test for string type arguements
+ assert(resipMin("hello","jello") == "hello");
+ cerr<<"min('hello','jello'): "<<resipMin("hello","jello")<<endl;
+ }
+ //test for strncasecmp
+ {
+ cerr<<"test strncasecmp"<<endl;
+ { //one upper case string and the other lower case
+ const char *str1 = "HELLO";
+ const char *str2 = "hell";
+ assert(strncasecmp(str1, str2, 4) == 0); }
+ { //both strings same
+ const char *str1 = "HELLO";
+ const char *str2 = "HELLO";
@dpocock
dpocock added a note

the compiler may actually make str1 and str2 point to the same copy of the "HELLO" in order to save RAM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ assert(strncasecmp(str1, str2, 4) == 0); }
+ { //for large strings
+ const char *str1 = "Once there lived in a forest a hair and a tortoise.The hare was very proud of his speed. He made fun of the tortoise for his slow speed. The tortoise challenged the hare to have a race with him. The hare accepted the challenge.The race started.The hare ran very fast. The tortoise was left much behind.";
+ const char *str2 = "Once there lived in a forest a hair and a tortoise.The hare was very proud of his speed. He made fun of the tortoise for his slow speed. The tortoise challenged the hare to have a race with him. The hare accepted the challenge.The race started.The hare ran very fast. The tortoise was left much behind.The race started. The crow was the referee. The hare ran very fast. The tortoise was left much behind.";
+ assert(strncasecmp(str1, str2, 200) == 0); }
+ { //one string is empty
+ const char *str1 = "";
+ const char *str2 = "hell";
+ assert(strncasecmp(str1, str2, 0) == 0); }
+ { //both are empty
+ const char *str1 = "";
+ const char *str2 = "";
+ assert(strncasecmp(str1, str2, 0) == 0); }
+ { //special character
+ const char *str1 = "~~`@##";
+ const char *str2 = "~~`#$@";
+ assert(strncasecmp(str1, str2, 3) == 0); }
+ }
+ //test for snprintf
+ {
+ cerr<<"test snprintf"<<endl;
+ char buffers [50];
+ int cx;
+ char *c = "hungary";
+ //string having some format specifiers
+ cx = snprintf( buffers, 50, "I have %f$ and I am %s.There are %d apples and %d banana on that stand",35.50,c,6,7);
+ assert(cx > 0);
+ //for n being less than string lenth
+ cx = snprintf( buffers, 5, "testing the snprintf function");
+ assert(cx > 0 );
+ //for n being greater than sting length
+ cx = snprintf( buffers, 15, "hello there");
+ assert(cx > 0);
@dpocock
dpocock added a note

for some of these smaller strings, could you test the exact value of cx that is expected?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ //for large string
+ char buffer1 [250];
+ cx = snprintf( buffer1, 250, "Once there lived in a forest a hair and a tortoise. The hare was very proud of his speed. He made fun of the tortoise for his slow speed. The tortoise challenged the hare to have a race with him. The hare accepted the challenge.");
+ assert(cx > 0);
+ char buffer2 [11];
+ //value of n and size of buffer exactly of same lengths as of string
+ cx = snprintf( buffer2, 11, "hellothere");
+ assert(cx > 0);
+ // value of n and size of buffer smaller tha length of string
+ cx = snprintf( buffer2, 11, "hello!,someone there ?");
+ assert(cx > 0);
+ }
+ cerr << "All OK" << endl;
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.