[PATCH] Refactor tests

Matthieu Patou mat at matws.net
Wed Aug 26 07:01:11 MDT 2009


Some tests were broken (and could lead to wrong results, ie. aab not after ab for instance).
String size are also more checked.
---
 source4/torture/ldap/ldap_sort.c |   39 ++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 16 deletions(-)

diff --git a/source4/torture/ldap/ldap_sort.c b/source4/torture/ldap/ldap_sort.c
index 4d732cf..da8ca25 100644
--- a/source4/torture/ldap/ldap_sort.c
+++ b/source4/torture/ldap/ldap_sort.c
@@ -47,10 +47,10 @@ bool torture_ldap_sort(struct torture_context *torture)
 	struct ldb_request *req;
 	struct ldb_result *ctx;
 	struct ldb_val* prev = NULL;
-	const char *prev_txt = NULL;
+	const unsigned char *prev_txt = NULL;
 	int prev_len = 0;
 	struct ldb_val* cur = NULL;
-	const char *cur_txt = NULL;
+	const unsigned char *cur_txt = NULL;
 	int cur_len = 0;
 	struct ldb_dn* dn;
 		 
@@ -107,30 +107,37 @@ bool torture_ldap_sort(struct torture_context *torture)
 				cur_len=cur->length;
 				prev_txt=prev->data;
 				prev_len=prev->length;
-				/* Remove leading whitespace as the sort function do so ... */
-				while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
-				while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
+				/* Remove  leading white space*/
+				if( prev_txt[0] == ' ') {
+					while ( cur_len && *cur_txt ==' ' ) { cur_txt++; cur_len--;}
+					while ( prev_len && *prev_txt == ' ' ) { prev_txt++; prev_len--;}
+				}
 				while( *(cur_txt) && *(prev_txt) && cur_len && prev_len ) {
 					j = toupper_m(*(prev_txt))-toupper_m(*(cur_txt));
 					if ( j > 0 ) {
-						/* Just check that is not due to trailling white space in prev_txt 
-						 * That is to say *cur_txt = 0 and prev_txt = 20 */
-						/* Remove trailling whitespace */
-						while ( *prev_txt == ' ' ) { prev_txt++; prev_len--;}
-						while ( *cur_txt == ' ' ) { cur_txt++; cur_len--;}
-						/* Now that potential whitespace are removed if we are at the end 
-						 * of the cur_txt then it means that in fact strings were identical
+						/* We are here because the previous element is "bigger" than
+						 * the current one.
+						 * It shouldn't be the case unless last char(s) of the previous
+						 * is/are white space
+						 */
+						if ( !*cur_txt && *prev_txt == ' ') {
+							while( prev_len && prev_txt[0] == ' ') { prev_txt++; prev_len--;}	
+						}
+						/* At this point if *prev_txt is not 0 then the data is 
+						 * not sorted in a good way as previous string > current string
 						 */
-						torture_assert(torture, *cur_txt && *prev_txt, "Data wrongly sorted");
+						torture_assert(torture, *prev_txt, "Data wrongly sorted");
 						break;
 					}
 					else
 					{
 						if ( j == 0 )
 						{
-							if ( *(cur_txt) == ' ') {
-								while ( cur_txt[0] == cur_txt[1] ) { cur_txt++; cur_len--;}
-								while ( prev_txt[0] == prev_txt[1] ) { prev_txt++; prev_len--;}
+							/* Remove multiple whitespaces if the previous string has at least one
+							 */ 
+							if( *prev_txt == ' ') {
+								while ( prev_len && *prev_txt == ' ' ) { prev_txt++; prev_len--;}
+								while ( cur_len && *cur_txt == ' ' ) { cur_txt++; cur_len--;}
 							}
 							cur_txt++;
 							prev_txt++;
-- 
1.6.0.4


--------------030605060108020309040500--


More information about the samba-technical mailing list