[sword-svn] r2128 - in trunk: src/keys tests tests/testsuite

scribe at www.crosswire.org scribe at www.crosswire.org
Sun Jan 6 00:45:25 MST 2008


Author: scribe
Date: 2008-01-06 00:45:24 -0700 (Sun, 06 Jan 2008)
New Revision: 2128

Modified:
   trunk/src/keys/versekey.cpp
   trunk/tests/testsuite/versekey.good
   trunk/tests/versekeytest.cpp
Log:
Fixed bug reported by Karl regarding bounds not always being honored


Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2007-12-29 23:26:01 UTC (rev 2127)
+++ trunk/src/keys/versekey.cpp	2008-01-06 07:45:24 UTC (rev 2128)
@@ -1079,93 +1079,94 @@
 {
 	error = 0;
 
-	if ((autocheck) && (!autonorm))	// only normalize if we were explicitely called or if autonorm is turned on
-		return;
+	if (((!autocheck) || (autonorm))	// only normalize if we were explicitely called or if autonorm is turned on
+               &&
+	          ((!headings) || ((verse) && (chapter)))) {		// this is cheeze and temporary until deciding what actions should be taken; so headings should only be turned on when positioning with Index() or incrementors
 
-	if ((headings) && ((!verse) || (!chapter)))		// this is cheeze and temporary until deciding what actions should be taken.
-		return;					// so headings should only be turned on when positioning with Index() or incrementors
+          while ((testament < 3) && (testament > 0)) {
 
-	while ((testament < 3) && (testament > 0)) {
+               if (book > BMAX[testament-1]) {
+                    book -= BMAX[testament-1];
+                    testament++;
+                    continue;
+               }
 
-		if (book > BMAX[testament-1]) {
-			book -= BMAX[testament-1];
-			testament++;
-			continue;
-		}
+               if (book < 1) {
+                    if (--testament > 0) {
+                         book += BMAX[testament-1];
+                    }
+                    continue;
+               }
 
-		if (book < 1) {
-			if (--testament > 0) {
-				book += BMAX[testament-1];
-			}
-			continue;
-		}
+               if (chapter > books[testament-1][book-1].chapmax) {
+                    chapter -= books[testament-1][book-1].chapmax;
+                    book++;
+                    continue;
+               }
 
-		if (chapter > books[testament-1][book-1].chapmax) {
-			chapter -= books[testament-1][book-1].chapmax;
-			book++;
-			continue;
-		}
+               if (chapter < 1) {
+                    if (--book > 0) {
+                         chapter += books[testament-1][book-1].chapmax;
+                    }
+                    else	{
+                         if (testament > 1) {
+                              chapter += books[0][BMAX[0]-1].chapmax;
+                         }
+                    }
+                    continue;
+               }
 
-		if (chapter < 1) {
-			if (--book > 0) {
-				chapter += books[testament-1][book-1].chapmax;
-			}
-			else	{
-				if (testament > 1) {
-					chapter += books[0][BMAX[0]-1].chapmax;
-				}
-			}
-			continue;
-		}
+               if (verse > books[testament-1][book-1].versemax[chapter-1]) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0]
+                    verse -= books[testament-1][book-1].versemax[chapter++ - 1];
+                    continue;
+               }
 
-		if (verse > books[testament-1][book-1].versemax[chapter-1]) { // -1 because e.g chapter 1 of Matthew is books[1][0].versemax[0]
-			verse -= books[testament-1][book-1].versemax[chapter++ - 1];
-			continue;
-		}
+               if (verse < 1) {
+                    if (--chapter > 0) {
+                         verse += books[testament-1][book-1].versemax[chapter-1];
+                    }
+                    else	{
+                         if (book > 1) {
+                              verse += books[testament-1][book-2].versemax[books[testament-1][book-2].chapmax-1];
+                         }
+                         else	{
+                              if (testament > 1) {
+                                   verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1];
+                              }
+                         }
+                    }
+                    continue;
+               }
 
-		if (verse < 1) {
-			if (--chapter > 0) {
-				verse += books[testament-1][book-1].versemax[chapter-1];
-			}
-			else	{
-				if (book > 1) {
-					verse += books[testament-1][book-2].versemax[books[testament-1][book-2].chapmax-1];
-				}
-				else	{
-					if (testament > 1) {
-						verse += books[0][BMAX[0]-1].versemax[books[0][BMAX[0]-1].chapmax-1];
-					}
-				}
-			}
-			continue;
-		}
+               break;  // If we've made it this far (all failure checks continue) we're ok
+          }
 
-		break;  // If we've made it this far (all failure checks continue) we're ok
-	}
+          if (testament > 2) {
+               testament = 2;
+               book      = BMAX[testament-1];
+               chapter   = books[testament-1][book-1].chapmax;
+               verse     = books[testament-1][book-1].versemax[chapter-1];
+               error     = KEYERR_OUTOFBOUNDS;
+          }
 
-	if (testament > 2) {
-		testament = 2;
-		book      = BMAX[testament-1];
-		chapter   = books[testament-1][book-1].chapmax;
-		verse     = books[testament-1][book-1].versemax[chapter-1];
-		error     = KEYERR_OUTOFBOUNDS;
-	}
+          if (testament < 1) {
+               error     = ((!headings) || (testament < 0) || (book < 0)) ? KEYERR_OUTOFBOUNDS : 0;
+               testament = ((headings) ? 0 : 1);
+               book      = ((headings) ? 0 : 1);
+               chapter   = ((headings) ? 0 : 1);
+               verse     = ((headings) ? 0 : 1);
+          }
 
-	if (testament < 1) {
-		error     = ((!headings) || (testament < 0) || (book < 0)) ? KEYERR_OUTOFBOUNDS : 0;
-		testament = ((headings) ? 0 : 1);
-		book      = ((headings) ? 0 : 1);
-		chapter   = ((headings) ? 0 : 1);
-		verse     = ((headings) ? 0 : 1);
-	}
-	if (_compare(UpperBound()) > 0) {
-		*this = UpperBound();
-		error = KEYERR_OUTOFBOUNDS;
-	}
-	if (_compare(LowerBound()) < 0) {
-		*this = LowerBound();
-		error = KEYERR_OUTOFBOUNDS;
-	}
+          // should we always perform bounds checks?  Tried but seems to cause infinite recursion
+          if (_compare(UpperBound()) > 0) {
+               setText(UpperBound());
+               error = KEYERR_OUTOFBOUNDS;
+          }
+          if (_compare(LowerBound()) < 0) {
+               setText(LowerBound());
+               error = KEYERR_OUTOFBOUNDS;
+          }
+     }
 }
 
 

Modified: trunk/tests/testsuite/versekey.good
===================================================================
--- trunk/tests/testsuite/versekey.good	2007-12-29 23:26:01 UTC (rev 2127)
+++ trunk/tests/testsuite/versekey.good	2008-01-06 07:45:24 UTC (rev 2128)
@@ -1,3 +1,5 @@
 x: Amos 1:5
 Amos 1:5
 Amos 1:5
+Error: 1
+Error: 1

Modified: trunk/tests/versekeytest.cpp
===================================================================
--- trunk/tests/versekeytest.cpp	2007-12-29 23:26:01 UTC (rev 2127)
+++ trunk/tests/versekeytest.cpp	2008-01-06 07:45:24 UTC (rev 2128)
@@ -37,12 +37,20 @@
      const char *bounds = "lk,acts";
      scope = parser.ParseVerseList(bounds, parser, true);
 
-     x = "1Sam.21.1";
+     VerseKey boundTest("lk", "acts");
+
+     boundTest.setText("Is.1.13");
+     std::cout << "Error: " << (int)boundTest.Error() << "\n";
+     boundTest.setText("1Sam.21.1");
+     std::cout << "Error: " << (int)boundTest.Error() << "\n";
+
+
+     x = "Is.1.13";
      scope = x;
 //     if (scope == x) std::cout << "Error restricting bounds: " << x.getText() << " is in " << bounds << "\n";
      if (!scope.Error()) std::cout << "Error restricting bounds: " << x.getText() << " is in " << bounds << "\n";
 
-     x = "Is.1.13";
+     x = "1Sam.21.1";
      scope = x;
      if (!scope.Error()) std::cout << "Error restricting bounds: " << x.getText() << " is in " << bounds << "\n";
 




More information about the sword-cvs mailing list