Module ll_test
[hide private]
[frames] | no frames]

Source Code for Module ll_test

   1  #!/usr/bin/env python 
   2  # 
   3  # Test the Linklist API. 
   4  # 
   5  # Note: This unit test will only operate correctly on a UNIX/Linux system. 
   6  # 
   7  # $Author: cnobile $ 
   8  # $Date: 2012-01-15 06:10:11 $ 
   9  # $Revision: 1.7 $ 
  10  # 
  11   
  12  import os, sys 
  13  import unittest 
  14  from ctypes import Structure, sizeof, string_at, cast, c_char, c_void_p 
  15   
  16  path = os.path.join(os.path.split(os.getcwd())[0], "src") 
  17  sys.path.insert(0, path) 
  18  #print sys.path 
  19   
  20  from dlinklist import APIException, FunctionException, DLinklist, Return, \ 
  21       SrchOrigin, SrchDir, InsertDir 
  22  from dlinklist.linklist import List 
  23   
24 -class Info(Structure):
25 _fields_ = ( 26 ('value', c_char * 50), 27 )
28 29
30 -class TestLibDll(unittest.TestCase):
31 """ 32 This class runs testunit test on all the function in my C{C} linklist 33 library. 34 """ 35
36 - def __init__(self, name):
37 """ 38 Initializes the C{TestLibDll} class. 39 40 1. Call the constructor of the base class. 41 2. Create an aggreget of the C{DLinklist} class. 42 3. Define an object to be used for a C{ctypes} C{POINTER} object. 43 44 @param name: The name used by the C{TestCase} class. 45 @raise LibraryNotFoundException: If the C{C} library cannot be found. 46 """ 47 super(TestLibDll, self).__init__(name) 48 self._dll = DLinklist(disableLogging=True) 49 self._list_p = None
50
51 - def setUp(self):
52 """ 53 Initialize the list for each unit test. 54 55 @return: C{None} 56 """ 57 # Create and initialize list 58 self._list_p = self._initList(sizeof(Info))
59 #print "Address of list_p: %s" % hex(cast(self._list_p, c_void_p).value) 60
61 - def tearDown(self):
62 """ 63 Destroy entire list. 64 65 @return: C{None} 66 """ 67 # Destroy list. 68 self._destroyList()
69
70 - def test_InfoType(self):
71 """ 72 Check that the C{Info} class is the correct type. 73 74 @return: C{None} 75 """ 76 msg = "Invalid Info type is not a subclass of ctypes Structure." 77 78 try: 79 self._dll.checkInfoType(Info()) 80 except: 81 self.fail(msg) 82 83 class BadInfo(object): 84 pass
85 86 try: 87 self._dll.checkInfoType(BadInfo()) 88 self.fail(msg) 89 except APIException: 90 pass
91
92 - def test_sizeofList(self):
93 """ 94 Test that the C{Python} C{List} object is the same size as the C{C} 95 C{List} structure. 96 97 @return: C{None} 98 """ 99 pSizeof = sizeof(List) 100 cSizeof = self._dll._lib._getListSize() 101 msg = "Python sizeof(List): %s, C sizeof(List): %s" % (pSizeof, cSizeof) 102 self.assertTrue(pSizeof == cSizeof, msg=msg)
103
104 - def test_DDL_Version(self):
105 """ 106 Test that a string is returned. 107 108 The C{C} function doc string:: 109 110 Ver: 1.3.0 Dec 24 2011 111 ------------------------------- 112 Developed by: Carl J. Nobile 113 Contributions: Charlie Buckheit 114 Graham Inchley 115 Wai-Sun Chia 116 Mark M. Feenstra 117 Lianqi Qiu 118 119 @return: C{None} 120 """ 121 devBy = " Developed by: Carl J. Nobile" 122 version = string_at(self._dll.version()) 123 124 try: 125 self.assertIn(devBy, version) # Python version => 2.7 126 except: 127 self.assertTrue(devBy in version)
128
129 - def test_DLL_IsListEmpty(self):
130 """ 131 Check that the list is empty. 132 133 @return: C{None} 134 """ 135 self._isListEmpty(test=True)
136
137 - def test_DLL_IsListFull(self):
138 """ 139 Check that the list is not full. 140 141 @return: C{None} 142 """ 143 self._isListFull(test=False)
144
145 - def test_DLL_GetNumberOfRecords(self):
146 """ 147 Check that the correct number of records are returned. 148 149 @return: C{None} 150 """ 151 # Test that list is empty 152 self._getNumberOfRecords(test=0) 153 # Test list with one record 154 value = "This is a test." 155 self._addRecord(Info(value)) 156 self._getNumberOfRecords(test=1)
157
158 - def test_DLL_SetSearchModes(self):
159 """ 160 Check that the correct return codes are returned when setting the 161 search modes. 162 163 @return: C{None} 164 """ 165 # Test the defaults 166 self._setSearchModes(SrchOrigin.ORIGIN_DEFAULT, 167 SrchDir.DIRECTION_DEFAULT) 168 # Test invalid SrchOrigin type 169 self._setSearchModes(10, SrchDir.DIRECTION_DEFAULT, 170 result=Return.NOT_MODIFIED) 171 # Test invalid SrchDir type 172 self._setSearchModes(SrchOrigin.ORIGIN_DEFAULT, 10, 173 result=Return.NOT_MODIFIED)
174
175 - def test_DLL_GetSearchModes(self):
176 """ 177 Check that the set search modes are returned. 178 179 @return: C{None} 180 """ 181 # Test the defaults 182 self._getSearchModes() 183 # Test SrchOrigin.TAIL and SrchDir.UP 184 self._setSearchModes(SrchOrigin.TAIL, SrchDir.UP) 185 self._getSearchModes(test=(SrchOrigin.TAIL, SrchDir.UP))
186
187 - def test_DLL_GetCurrentIndex(self):
188 """ 189 Check that the current index is returned. 190 191 @return: C{None} 192 """ 193 # Test no records 194 self._getCurrentIndex() 195 # Test one record 196 value = "This is a test." 197 self._addRecord(Info(value)) 198 self._getCurrentIndex(test=1)
199
200 - def test_DLL_CurrentPointerToHead(self):
201 """ 202 Check that the current pointer gets moved to the head of the list 203 properly and that the correct return codes are returned. 204 205 @return: C{None} 206 """ 207 # Test no records 208 self._currentPointerToHead(result=Return.NULL_LIST) 209 # Test with two records 210 value = "This is test record one." 211 self._addRecord(Info(value)) 212 value = "This is test record two." 213 self._addRecord(Info(value)) 214 self._getCurrentIndex(test=2) 215 self._currentPointerToHead() 216 self._getCurrentIndex(test=1)
217
218 - def test_DLL_CurrentPointerToTail(self):
219 """ 220 Check that the current pointer gets moved to the tail of the list 221 properly and that the correct return codes are returned. 222 223 @return: C{None} 224 """ 225 # Test no records 226 self._currentPointerToTail(result=Return.NULL_LIST) 227 # Test with two records 228 value = "This is test record one." 229 self._addRecord(Info(value)) 230 value = "This is test record two." 231 self._addRecord(Info(value)) 232 self._currentPointerToHead() 233 self._getCurrentIndex(test=1) 234 self._currentPointerToTail() 235 self._getCurrentIndex(test=2)
236
237 - def test_DLL_IncrementCurrentPointer(self):
238 """ 239 Check that the current pointer gets incremented properly and that the 240 correct return codes are returned. 241 242 @return: C{None} 243 """ 244 # Test no records 245 self._incrementCurrentPointer(result=Return.NULL_LIST) 246 # Test with two records 247 value = "This is test record one." 248 self._addRecord(Info(value)) 249 value = "This is test record two." 250 self._addRecord(Info(value)) 251 self._currentPointerToHead() 252 self._incrementCurrentPointer() 253 self._getCurrentIndex(test=2) 254 # Test past end 255 self._incrementCurrentPointer(result=Return.NOT_FOUND)
256
257 - def test_DLL_DecrementCurrentPointer(self):
258 """ 259 Check that the current pointer gets decremented properly and that the 260 correct return codes are returned. 261 262 @return: C{None} 263 """ 264 # Test no records 265 self._decrementCurrentPointer(result=Return.NULL_LIST) 266 # Test with two records 267 value = "This is test record one." 268 self._addRecord(Info(value)) 269 value = "This is test record two." 270 self._addRecord(Info(value)) 271 self._decrementCurrentPointer() 272 self._getCurrentIndex(test=1) 273 # Test past beginning 274 self._decrementCurrentPointer(result=Return.NOT_FOUND)
275
276 - def test_DLL_Store_RestoreCurrentPointer(self):
277 """ 278 Check that the store and restore of the current pointer is properly 279 done and the correct return codes are returned. 280 281 @return: C{None} 282 """ 283 # Test no records 284 self._storeCurrentPointer(result=Return.NOT_FOUND) 285 self._restoreCurrentPointer(result=Return.NOT_FOUND) 286 # Test with two records 287 value = "This is test record one." 288 self._addRecord(Info(value)) 289 value = "This is test record two." 290 self._addRecord(Info(value)) 291 self._storeCurrentPointer() 292 self._decrementCurrentPointer() 293 self._getCurrentIndex(test=1) 294 self._restoreCurrentPointer() 295 self._getCurrentIndex(test=2)
296
297 - def test_DLL_AddRecord(self):
298 """ 299 Check that records are added to the link list properly, the index 300 values are correct after each add, and the correct return codes are 301 returned. 302 303 @return: C{None} 304 """ 305 # Test non-sorted addRecord. 306 value = "This is a test." 307 self._addRecord(Info(value)) 308 self._getCurrentIndex(test=1) 309 self._getNumberOfRecords(test=1) 310 self._deleteEntireList() 311 self._getCurrentIndex(test=0) 312 self._getNumberOfRecords(test=0) 313 # Test with three records 314 values = [] 315 values.append("ZZZZ - This is test record one.") 316 values.append("AAAA - This is test record two.") 317 values.append("NNNN - This is test record three.") 318 319 for value in values: 320 self._addRecord(Info(value), self._dll.compare()) 321 322 # This next test will fail in version 1.2.1 and below. 323 self._getCurrentIndex(test=2) 324 values.sort() 325 #print values 326 self._currentPointerToHead() 327 self._getCurrentIndex(test=1) 328 size = len(values) 329 330 for idx in range(size): 331 self._getCurrentRecord(Info(), test=values[idx]) 332 idx < (size-1) and self._incrementCurrentPointer() 333 334 self.assertTrue(idx == (size-1))
335
336 - def test_DLL_InsertRecord(self):
337 """ 338 Check that inserted records are added properly based on C{InsertDir}, 339 the index values are correct after each insert, and the correct return 340 codes are returned. 341 342 @return: C{None} 343 """ 344 values = [] 345 values.append("ZZZZ - This is test record one.") 346 values.append("AAAA - This is test record two.") 347 values.append("NNNN - This is test record three.") 348 record = Info(values[0]) 349 self._insertRecord(record, InsertDir.ABOVE) 350 self._getNumberOfRecords(test=1) 351 record = Info(values[1]) 352 self._insertRecord(record, InsertDir.ABOVE) 353 self._getNumberOfRecords(test=2) 354 record = Info(values[2]) 355 self._insertRecord(record, InsertDir.BELOW) 356 self._getNumberOfRecords(test=3) 357 self._currentPointerToHead() 358 record = Info() 359 values.sort() 360 size = len(values) 361 362 for idx in range(size): 363 self._getCurrentRecord(record, test=values[idx]) 364 #print record.value 365 idx < (size-1) and self._incrementCurrentPointer() 366 367 self.assertTrue(idx == (size-1))
368
369 - def test_DLL_SwapRecord(self):
370 """ 371 Check that the current record is swapped correctly based on 372 C{InsertDir}, the index values are correct after each swap, and the 373 correct return codes are returned. 374 375 @return: C{None} 376 """ 377 # Test no records 378 self._swapRecord(InsertDir.ABOVE, result=Return.NULL_LIST) 379 # Test invalid direction 380 values = [] 381 values.append("ZZZZ - This is test record one.") 382 values.append("AAAA - This is test record two.") 383 values.append("NNNN - This is test record three.") 384 385 for value in values: 386 self._addRecord(Info(value)) 387 388 self._swapRecord(10, result=Return.NOT_MODIFIED) 389 self._getNumberOfRecords(test=3) 390 # Test no record after tail 391 self._getCurrentIndex(test=3) 392 self._swapRecord(InsertDir.BELOW, result=Return.NOT_FOUND) 393 # Test that the three records are in the correct order. 394 self._getCurrentIndex(test=3) 395 self._decrementCurrentPointer() 396 self._swapRecord(InsertDir.ABOVE) 397 self._getCurrentIndex(test=1) 398 self._incrementCurrentPointer() 399 self._swapRecord(InsertDir.BELOW) 400 # Test no record before head 401 self._currentPointerToHead() 402 self._swapRecord(InsertDir.ABOVE, result=Return.NOT_FOUND) 403 # Continue with correct order test. 404 record = Info() 405 values.sort() 406 size = len(values) 407 408 for idx in range(size): 409 self._getCurrentRecord(record, test=values[idx]) 410 #print record.value 411 idx < (size-1) and self._incrementCurrentPointer() 412 413 self.assertTrue(idx == (size-1))
414
415 - def test_DLL_UpdateCurrentRecord(self):
416 """ 417 Check that a record gets updated correctly, the index values are 418 correct after each update, and the correct return codes are returned. 419 420 @return: C{None} 421 """ 422 # Test no records 423 value = "This is a text." 424 self._updateCurrentRecord(Info(value), 425 result=Return.NULL_LIST) 426 self._getCurrentIndex(test=0) 427 # Test that the record got updated 428 self._addRecord(Info(value)) 429 self._getCurrentRecord(Info(), test=value) 430 self._getCurrentIndex(test=1) 431 value = "This is another text." 432 self._updateCurrentRecord(Info(value)) 433 self._getCurrentIndex(test=1) 434 self._getCurrentRecord(Info(), test=value) 435 self._getCurrentIndex(test=1)
436
437 - def test_DLL_DeleteCurrentRecord(self):
438 """ 439 Check that a record gets deleted correctly, the index values are 440 correct after each update, and the correct return codes are returned. 441 442 @return: C{None} 443 """ 444 # Test no records 445 self._deleteCurrentRecord(result=Return.NULL_LIST) 446 self._getCurrentIndex(test=0) 447 # Test that the record got deleted 448 value = "This is a text." 449 self._addRecord(Info(value)) 450 self._getCurrentIndex(test=1) 451 self._deleteCurrentRecord() 452 self._isListEmpty(test=True)
453
454 - def test_DLL_DeleteEntireList(self):
455 """ 456 Check that the entire list is deleted properly, the index values are 457 correct after the delete, and the correct return codes are returned. 458 459 @return: C{None} 460 """ 461 # Test no records 462 self._deleteEntireList(result=Return.NULL_LIST) 463 # Test thst the list gets deleted 464 values = [] 465 values.append("ZZZZ - This is test record one.") 466 values.append("AAAA - This is test record two.") 467 values.append("NNNN - This is test record three.") 468 469 for value in values: 470 self._addRecord(Info(value)) 471 472 self._getNumberOfRecords(test=3) 473 self._deleteEntireList() 474 self._isListEmpty(test=True)
475
476 - def test_DLL_FindRecord(self):
477 """ 478 Check that records are found correctly, the index values are correct 479 after each query, and the correct return codes are returned. 480 481 @return: C{None} 482 """ 483 # Test for null function pointer 484 self._findRecord(Info(), Info(), None, 485 result=Return.NULL_FUNCTION) 486 # Test no records 487 self._findRecord(Info(), Info(), self._dll.compare(), 488 result=Return.NULL_LIST) 489 # Test that record if found 490 values = [] 491 values.append("ZZZZ - This is test record one.") 492 values.append("AAAA - This is test record two.") 493 values.append("NNNN - This is test record three.") 494 495 for value in values: 496 self._addRecord(Info(value)) 497 498 self._getNumberOfRecords(test=3) 499 record = Info() 500 self._findRecord(record, Info(values[1]), self._dll.compare()) 501 # Test record not found 502 self._findRecord(record, Info("Record not found."), 503 self._dll.compare(), result=Return.NOT_FOUND)
504
505 - def test_DLL_FindNthRecord(self):
506 """ 507 Check that records are found correctly based on the skip value, the 508 index values are correct after each query, and the correct return 509 codes are returned. 510 511 @return: C{None} 512 """ 513 # Test no records 514 self._findNthRecord(Info(), 1, result=Return.NULL_LIST) 515 # Test for the Nth record, step = 1 then 5 516 # (Uses defaults in the list struct, SrchOrigin.HEAD and SrchDir.DOWN) 517 values = [] 518 values.append("ZZZZ - This is test record one.") 519 values.append("AAAA - This is test record two.") 520 values.append("NNNN - This is test record three.") 521 values.append("YYYY - This is test record four.") 522 values.append("BBBB - This is test record five.") 523 values.append("MMMM - This is test record six.") 524 525 for value in values: 526 self._addRecord(Info(value)) 527 528 self._getNumberOfRecords(test=6) 529 self._getCurrentIndex(test=6) 530 self._findNthRecord(Info(), 1, test=values[1]) 531 self._getCurrentIndex(test=2) 532 self._findNthRecord(Info(), 5, test=values[5]) 533 self._getCurrentIndex(test=6) 534 # Test invalid skip value with SrchOrigin.HEAD and SrchDir.DOWN 535 self._findNthRecord(Info(), 0, test=values[1], 536 result=Return.NOT_FOUND) 537 self._findNthRecord(Info(), 6, test=values[1], 538 result=Return.NOT_FOUND) 539 # Test change search mode to SrchOrigin.TAIL and SrchDir.UP 540 self._setSearchModes(SrchOrigin.TAIL, SrchDir.UP) 541 self._findNthRecord(Info(), 1, test=values[4]) 542 self._getCurrentIndex(test=5) 543 self._findNthRecord(Info(), 5, test=values[0]) 544 self._getCurrentIndex(test=1) 545 # Test invalid skip value with SrchOrigin.TAIL and SrchDir.UP 546 self._findNthRecord(Info(), 6, test=values[5], 547 result=Return.NOT_FOUND) 548 # Test change search mode to SrchOrigin.CURRENT and SrchDir.DOWN 549 self._setSearchModes(SrchOrigin.CURRENT, SrchDir.DOWN) 550 # TODO -- enhance the increment and decrement current pointer to 551 # to increment or decrement a number of records. 552 self._incrementCurrentPointer() 553 self._incrementCurrentPointer() 554 self._findNthRecord(Info(), 1, test=values[3]) 555 self._getCurrentIndex(test=4) 556 # Test invalid skip value with SrchOrigin.CURRENT and SrchDir.DOWN 557 self._findNthRecord(Info(), 3, test=values[5], 558 result=Return.NOT_FOUND) 559 self._getCurrentIndex(test=4) 560 # Test change search mode to SrchOrigin.CURRENT and SrchDir.UP 561 self._setSearchModes(SrchOrigin.CURRENT, SrchDir.UP) 562 self._findNthRecord(Info(), 1, test=values[2]) 563 self._getCurrentIndex(test=3) 564 # Test invalid skip value with SrchOrigin.CURRENT and SrchDir.UP 565 self._findNthRecord(Info(), 3, test=values[0], 566 result=Return.NOT_FOUND) 567 self._getCurrentIndex(test=3)
568
569 - def test_DLL_GetCurrentRecord(self):
570 """ 571 Check that the current record is returned correctly, the index values 572 are correct after the get, and the correct return codes are returned. 573 574 @return: C{None} 575 """ 576 # Test no records 577 self._getCurrentRecord(Info(), result=Return.NULL_LIST) 578 self._getCurrentIndex(test=0) 579 # Test for curent record 580 value = "This is test record." 581 self._addRecord(Info(value)) 582 self._getCurrentRecord(Info(), test=value) 583 self._getCurrentIndex(test=1)
584
585 - def test_DLL_GetPriorRecord(self):
586 """ 587 Check that the prior record is returned correctly, the index values 588 are correct after the get, and the correct return codes are returned. 589 590 @return: C{None} 591 """ 592 # Test no records 593 self._getPriorRecord(Info(), result=Return.NULL_LIST) 594 # Test for curent record 595 values = [] 596 values.append("ZZZZ - This is test record one.") 597 values.append("AAAA - This is test record two.") 598 599 for value in values: 600 self._addRecord(Info(value)) 601 602 self._currentPointerToTail() 603 self._getPriorRecord(Info(), test=values[0]) 604 self._getCurrentIndex(test=1)
605
606 - def test_DLL_GetNextRecord(self):
607 """ 608 Check that the next record is returned correctly, the index values are 609 correct after the get, and the correct return codes are returned. 610 611 @return: C{None} 612 """ 613 # Test no records 614 self._getNextRecord(Info(), result=Return.NULL_LIST) 615 # Test for curent record 616 values = [] 617 values.append("ZZZZ - This is test record one.") 618 values.append("AAAA - This is test record two.") 619 620 for value in values: 621 self._addRecord(Info(value)) 622 623 self._currentPointerToHead() 624 self._getNextRecord(Info(), test=values[1]) 625 self._getCurrentIndex(test=2)
626
627 - def test_DLL_Save_LoadList(self):
628 """ 629 Check that the list is saved and loaded correctly, the index values are 630 correct after the loads, the sorting on load is done properly, and the 631 correct return codes are returned. 632 633 @return: C{None} 634 """ 635 filePath = "/tmp/unittest.data" 636 # Test no records 637 self._saveList(filePath, result=Return.NULL_LIST) 638 # Test saving list to dick 639 values = [] 640 values.append("ZZZZ - This is test record one.") 641 values.append("AAAA - This is test record two.") 642 values.append("NNNN - This is test record three.") 643 values.append("YYYY - This is test record four.") 644 values.append("BBBB - This is test record five.") 645 values.append("MMMM - This is test record six.") 646 647 for value in values: 648 self._addRecord(Info(value)) 649 650 self._getNumberOfRecords(test=6) 651 self._saveList(filePath) 652 # Test already has data in list. 653 self._saveList(filePath, result=Return.NOT_MODIFIED) 654 # Test load list. 655 self._loadList(filePath, self._dll.compare()) 656 # The current index is an arbitrary number depending on the sort 657 # algorithm used. This next test will fail in version 1.2.1 and below. 658 self._getCurrentIndex(test=3) 659 self._currentPointerToHead() 660 self._getCurrentIndex(test=1) 661 # Test open error. 662 self._loadList("", self._dll.compare(), result=Return.OPEN_ERROR) 663 self._getCurrentIndex(test=1) 664 os.remove(filePath)
665 666 # 667 # Methods to interface into ctypes. 668 #
669 - def _initList(self, infoSize):
670 """ 671 Prepare the link list for use and asserts that there are no 672 C{APIException} or C{FunctionException} exceptions, and the C{list_p} 673 object is valid. 674 675 @param infoSize: The size in bytes of the user defined C{Info} class. 676 @type infoSize: C{int} 677 @return: A pinter to the link list. 678 @rtype: C{ctypes POINTER} 679 """ 680 try: 681 list_p = self._dll.create(infoSize) 682 except APIException, e: 683 self.fail(e) 684 except FunctionException, e: 685 self.fail(e) 686 687 msg = "DLL_CreateList failed, list_p: %s." 688 self.assertTrue(list_p not in (0, None), 689 msg=msg % hex(cast(list_p, c_void_p).value)) 690 return list_p
691
692 - def _destroyList(self):
693 """ 694 Executes the C{destroyList} method and asserts that there are no 695 C{APIException} exceptions. 696 697 @return: C{None} 698 """ 699 try: 700 self._dll.destroyList() 701 except APIException, e: 702 self.fail(e)
703
704 - def _isListEmpty(self, test=True):
705 """ 706 Executes the C{isListEmpty} method, asserts that there are no 707 C{APIException} exceptions, and asserts that the returned value is 708 correct. 709 710 @keyword test: The expected value, the default is C{True}. 711 @type test: C{bool} 712 @return: C{None} 713 """ 714 try: 715 retval = self._dll.isListEmpty() 716 except APIException, e: 717 self.fail(e) 718 719 msg = "retval: %s, test: %s" 720 self.assertTrue(retval == test, msg=msg % (retval, test))
721
722 - def _isListFull(self, test=True):
723 """ 724 Execute the C{isListFull} method, asserts that there are no 725 C{APIException} exceptions, and asserts that the return value is 726 correct. 727 728 @keyword test: The expected value, the default is C{True}. 729 @type test: C{bool} 730 @return: C{None} 731 """ 732 try: 733 retval = self._dll.isListFull() 734 except APIException, e: 735 self.fail(e) 736 737 msg = "retval: %s, test: %s" 738 self.assertTrue(retval == test, msg=msg % (retval, test))
739
740 - def _getNumberOfRecords(self, test=0):
741 """ 742 Execute the C{getNumberOfRecords} method, asserts that there are no 743 C{APIException} exceptions, and asserts that the returned value is 744 correct. 745 746 @keyword test: The expected value, the default is C{0}. 747 @type test: C{int} 748 @return: C{None} 749 """ 750 try: 751 retval = self._dll.getNumberOfRecords() 752 except APIException, e: 753 self.fail(e) 754 755 msg = "retval: %s, test: %s" 756 self.assertTrue(retval == test, msg=msg % (retval, test))
757
758 - def _setSearchModes(self, origin, dir, result=Return.NORMAL):
759 """ 760 Execute the C{setSearchModes} method, asserts that there are no 761 C{APIException} or C{FunctionException} exceptions, and asserts that 762 the return code is correct. 763 764 @keyword result: The expected value, the default is C{Return.NORMAL}. 765 @type result: C{Return} 766 @return: C{None} 767 """ 768 try: 769 retval = self._dll.setSearchModes(origin, dir) 770 except APIException, e: 771 self.fail(e) 772 except FunctionException, e: 773 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 774 self.assertTrue(e.getRetval() == result, msg=msg)
775
776 - def _getSearchModes(self, test=(SrchOrigin.HEAD, SrchDir.DOWN)):
777 """ 778 Execute the C{getSearchModes} method, asserts that there are no 779 C{APIException} exceptions, and asserts that the returned C{tuple} is 780 correct. 781 782 @keyword test: The expected value, the default is 783 C{(SrchOrigin.HEAD, SrchDir.DOWN)}. 784 @type test: C{tuple} of C{SrchOrigin} and C{SrchDir} 785 @return: C{None} 786 """ 787 try: 788 origin, direction = self._dll.getSearchModes() 789 except APIException, e: 790 self.fail(e) 791 792 #self._dll._lib._printList(self._list_p) 793 msg = "SrchOrigin.%s: %s" % SrchOrigin.getMessage(origin) 794 self.assertTrue(origin == test[0], msg=msg) 795 msg = "SrchDir.%s: %s" % SrchDir.getMessage(direction) 796 self.assertTrue(direction == test[1], msg=msg)
797
798 - def _getCurrentIndex(self, test=0):
799 """ 800 Execute the C{getCurrentIndex} method, asserts that there are no 801 C{APIException} exceptions, and asserts that the returned value is 802 correct. 803 804 @keyword test: The expected value, the default is C{0}. 805 @type test: C{int} 806 @return: C{None} 807 """ 808 try: 809 retval = self._dll.getCurrentIndex() 810 except APIException, e: 811 self.fail(e) 812 813 msg = "retval: %s, test: %s" 814 self.assertTrue(retval == test, msg=msg % (retval, test))
815
816 - def _currentPointerToHead(self, result=Return.NORMAL):
817 """ 818 Execute the C{currentPointerToHead} method, asserts that there are no 819 C{APIException} or C{FunctionException} exceptions, and asserts that 820 the return code is correct. 821 822 @keyword result: The expected value, the default is C{Return.NORMAL}. 823 @type result: C{Return} 824 @return: C{None} 825 """ 826 try: 827 retval = self._dll.currentPointerToHead() 828 except APIException, e: 829 self.fail(e) 830 except FunctionException, e: 831 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 832 self.assertTrue(e.getRetval() == result, msg=msg)
833
834 - def _currentPointerToTail(self, result=Return.NORMAL):
835 """ 836 Execute the C{currentPointerToTail} method, asserts that there are no 837 C{APIException} or C{FunctionException} exceptions, and asserts that 838 the return code is correct. 839 840 @keyword result: The expected value, the default is C{Return.NORMAL}. 841 @type result: C{Return} 842 @return: C{None} 843 """ 844 try: 845 retval = self._dll.currentPointerToTail() 846 except APIException, e: 847 self.fail(e) 848 except FunctionException, e: 849 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 850 self.assertTrue(e.getRetval() == result, msg=msg)
851
852 - def _incrementCurrentPointer(self, result=Return.NORMAL):
853 """ 854 Execute the C{incrementCurrentPointer} method, asserts that there are 855 no C{APIException} or C{FunctionException} exceptions, and asserts that 856 the return code is correct. 857 858 @keyword result: The expected value, the default is C{Return.NORMAL}. 859 @type result: C{Return} 860 @return: C{None} 861 """ 862 try: 863 retval = self._dll.incrementCurrentPointer() 864 except APIException, e: 865 self.fail(e) 866 except FunctionException, e: 867 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 868 self.assertTrue(e.getRetval() == result, msg=msg)
869
870 - def _decrementCurrentPointer(self, result=Return.NORMAL):
871 """ 872 Execute the C{decrementCurrentPointer} method, asserts that there are 873 no C{APIException} or C{FunctionException} exceptions, and asserts that 874 the return code is correct. 875 876 @keyword result: The expected value, the default is C{Return.NORMAL}. 877 @type result: C{Return} 878 @return: C{None} 879 """ 880 try: 881 retval = self._dll.decrementCurrentPointer() 882 except APIException, e: 883 self.fail(e) 884 except FunctionException, e: 885 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 886 self.assertTrue(e.getRetval() == result, msg=msg)
887
888 - def _storeCurrentPointer(self, result=Return.NORMAL):
889 """ 890 Execute the C{storeCurrentPointer} method, asserts that there are no 891 C{APIException} or C{FunctionException} exceptions, and asserts that 892 the return code is correct. 893 894 @keyword result: The expected value, the default is C{Return.NORMAL}. 895 @type result: C{Return} 896 @return: C{None} 897 """ 898 try: 899 retval = self._dll.storeCurrentPointer() 900 except APIException, e: 901 self.fail(e) 902 except FunctionException, e: 903 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 904 self.assertTrue(e.getRetval() == result, msg=msg)
905
906 - def _restoreCurrentPointer(self, result=Return.NORMAL):
907 """ 908 Execute the C{restoreCurrentPointer} method, asserts that there are no 909 C{APIException} or C{FunctionException} exceptions, and asserts that 910 the return code is correct. 911 912 @keyword result: The expected value, the default is C{Return.NORMAL}. 913 @type result: C{Return} 914 @return: C{None} 915 """ 916 try: 917 retval = self._dll.restoreCurrentPointer() 918 except APIException, e: 919 self.fail(e) 920 except FunctionException, e: 921 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 922 self.assertTrue(e.getRetval() == result, msg=msg)
923
924 - def _addRecord(self, info, pFun=None, result=Return.NORMAL):
925 """ 926 Execute the C{addRecord} method, asserts that there are no 927 C{APIException} or C{FunctionException} exceptions, and asserts that 928 the return code is correct. 929 930 @param info: An instance of the C{Info} class. 931 @type info: C{Info} 932 @keyword pFun: An optional compare function, the default is C{None}. 933 @type pFun: C{ctypes CFUNCTYPE} 934 @keyword result: The expected value, the default is C{Return.NORMAL}. 935 @type result: C{Return} 936 @return: C{None} 937 """ 938 try: 939 retval = self._dll.addRecord(info, pFun=pFun) 940 except APIException, e: 941 self.fail(e) 942 except FunctionException, e: 943 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 944 self.assertTrue(e.getRetval() == result, msg=msg)
945
946 - def _insertRecord(self, info, dir, result=Return.NORMAL):
947 """ 948 Execute the C{insertRecord} method, asserts that there are no 949 C{APIException} or C{FunctionException} exceptions, and asserts that 950 the return code is correct. 951 952 @param info: An instance of the C{Info} class. 953 @type info: C{Info} 954 @param dir: The direction to insert indicator. 955 @type dir: C{InsertDir} 956 @keyword result: The expected value, the default is C{Return.NORMAL}. 957 @type result: C{Return} 958 @return: C{None} 959 """ 960 try: 961 retval = self._dll.insertRecord(info, dir) 962 except APIException, e: 963 self.fail(e) 964 except FunctionException, e: 965 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 966 self.assertTrue(e.getRetval() == result, msg=msg)
967
968 - def _swapRecord(self, dir, result=Return.NORMAL):
969 """ 970 Execute the C{swapRecord} method, asserts that there are no 971 C{APIException} or C{FunctionException} exceptions, and asserts that 972 the return code is correct. 973 974 @param dir: The direction to swap indicator. 975 @type dir: C{InsertDir} 976 @keyword result: The expected value, the default is C{Return.NORMAL}. 977 @type result: C{Return} 978 @return: C{None} 979 """ 980 try: 981 retval = self._dll.swapRecord(dir) 982 except APIException, e: 983 self.fail(e) 984 except FunctionException, e: 985 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 986 self.assertTrue(e.getRetval() == result, msg=msg)
987
988 - def _updateCurrentRecord(self, record, result=Return.NORMAL):
989 """ 990 Execute the C{updateCurrentRecord} method, asserts that there are no 991 C{APIException} or C{FunctionException} exceptions, and asserts that 992 the return code is correct. 993 994 @param record: Will contains the results of the get. 995 @type record: C{Info} 996 @keyword result: The expected value, the default is C{Return.NORMAL}. 997 @type result: C{Return} 998 @return: C{None} 999 """ 1000 try: 1001 retval = self._dll.updateCurrentRecord(record) 1002 except APIException, e: 1003 self.fail(e) 1004 except FunctionException, e: 1005 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1006 self.assertTrue(e.getRetval() == result, msg=msg)
1007
1008 - def _deleteCurrentRecord(self, result=Return.NORMAL):
1009 """ 1010 Execute the C{} method, asserts that there are no 1011 C{APIException} or C{FunctionException} exceptions, and asserts that 1012 the return code is correct. 1013 1014 @keyword result: The expected value, the default is C{Return.NORMAL}. 1015 @type result: C{Return} 1016 @return: C{None} 1017 """ 1018 try: 1019 retval = self._dll.deleteCurrentRecord() 1020 except APIException, e: 1021 self.fail(e) 1022 except FunctionException, e: 1023 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1024 self.assertTrue(e.getRetval() == result, msg=msg)
1025
1026 - def _deleteEntireList(self, result=Return.NORMAL):
1027 """ 1028 Execute the C{deleteAllNodes} method, asserts that there are no 1029 C{APIException} or C{FunctionException} exceptions, and asserts that 1030 the return code is correct. 1031 1032 @keyword result: The expected value, the default is C{Return.NORMAL}. 1033 @type result: C{Return} 1034 @return: C{None} 1035 """ 1036 try: 1037 retval = self._dll.deleteAllNodes() 1038 except APIException, e: 1039 self.fail(e) 1040 except FunctionException, e: 1041 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1042 self.assertTrue(e.getRetval() == result, msg=msg)
1043
1044 - def _findRecord(self, record, match, pFun=None, result=Return.NORMAL):
1045 """ 1046 Execute the C{findRecord} method, asserts that there are no 1047 C{APIException} or C{FunctionException} exceptions, assert that the 1048 test value is correct, and asserts that the return code is correct. 1049 1050 @param record: Will contain the results of the find. 1051 @type record: C{Info} 1052 @param match: Provides the query information. 1053 @type match: C{Info} 1054 @keyword pFun: An optional compare function, the default is C{None}. 1055 @type pFun: C{ctypes CFUNCTYPE} 1056 @keyword result: The expected value, the default is C{Return.NORMAL}. 1057 @type result: C{Return} 1058 @return: C{None} 1059 """ 1060 try: 1061 retval = self._dll.findRecord(record, match, pFun=pFun) 1062 except APIException, e: 1063 self.fail(e) 1064 except FunctionException, e: 1065 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1066 self.assertTrue(e.getRetval() == result, msg=msg) 1067 1068 msg = "record.value: %s, match.value: %s" % (record.value, match.value) 1069 self.assertTrue(record.value == match.value or 1070 result == Return.NOT_FOUND, msg=msg)
1071
1072 - def _findNthRecord(self, record, skip, test="", result=Return.NORMAL):
1073 """ 1074 Execute the C{findNthRecord} method, asserts that there are no 1075 C{APIException} or C{FunctionException} exceptions, assert that the 1076 test value is correct, and asserts that the return code is correct. 1077 1078 @param record: Will contain the results of the find. 1079 @type record: C{Info} 1080 @param skip: The number of records to skip over. 1081 @type skip: C{int} 1082 @keyword test: Value to test, default is an empty string. 1083 @type test: C{str} 1084 @keyword result: The expected value, the default is C{Return.NORMAL}. 1085 @type result: C{Return} 1086 @return: C{None} 1087 """ 1088 try: 1089 retval = self._dll.findNthRecord(record, skip) 1090 except APIException, e: 1091 self.fail(e) 1092 except FunctionException, e: 1093 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1094 self.assertTrue(e.getRetval() == result, msg=msg) 1095 1096 #print "record.value: %s, test: %s" % (record.value, test) 1097 msg = "record.value: %s, test: %s" % (record.value, test) 1098 self.assertTrue(record.value == test or 1099 result == Return.NOT_FOUND, msg=msg)
1100
1101 - def _getCurrentRecord(self, record, test="", result=Return.NORMAL):
1102 """ 1103 Execute the C{getCurrentRecord} method, asserts that there are no 1104 C{APIException} or C{FunctionException} exceptions, assert that the 1105 test value is correct, and asserts that the return code is correct. 1106 1107 @param record: Will contain the results of the find. 1108 @type record: C{Info} 1109 @keyword test: Value to test, default is an empty string. 1110 @type test: C{str} 1111 @keyword result: The expected value, the default is C{Return.NORMAL}. 1112 @type result: C{Return} 1113 @return: C{None} 1114 """ 1115 try: 1116 retval = self._dll.getCurrentRecord(record) 1117 except APIException, e: 1118 self.fail(e) 1119 except FunctionException, e: 1120 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1121 self.assertTrue(e.getRetval() == result, msg=msg) 1122 1123 msg = "record.value: %s, test: %s" % (record.value, test) 1124 self.assertTrue(test == record.value, msg=msg)
1125
1126 - def _getPriorRecord(self, record, test="", result=Return.NORMAL):
1127 """ 1128 Execute the C{getPriorRecord} method, asserts that there are no 1129 C{APIException} or C{FunctionException} exceptions, assert that the 1130 test value is correct, and asserts that the return code is correct. 1131 1132 @param record: Will contain the results of the find. 1133 @type record: C{Info} 1134 @keyword test: Value to test, default is an empty string. 1135 @type test: C{str} 1136 @keyword result: The expected value, the default is C{Return.NORMAL}. 1137 @type result: C{Return} 1138 @return: C{None} 1139 """ 1140 try: 1141 retval = self._dll.getPriorRecord(record) 1142 except APIException, e: 1143 self.fail(e) 1144 except FunctionException, e: 1145 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1146 self.assertTrue(e.getRetval() == result, msg=msg) 1147 1148 msg = "record.value: %s, test: %s" % (record.value, test) 1149 self.assertTrue(test == record.value, msg=msg)
1150
1151 - def _getNextRecord(self, record, test="", result=Return.NORMAL):
1152 """ 1153 Execute the C{getNextRecord} method, asserts that there are no 1154 C{APIException} or C{FunctionException} exceptions, assert that the 1155 test value is correct, and asserts that the return code is correct. 1156 1157 @param record: Will contain the results of the find. 1158 @type record: C{Info} 1159 @keyword test: Value to test, default is an empty string. 1160 @type test: C{str} 1161 @keyword result: The expected value, the default is C{Return.NORMAL}. 1162 @type result: C{Return} 1163 @return: C{None} 1164 """ 1165 try: 1166 retval = self._dll.getNextRecord(record) 1167 except APIException, e: 1168 self.fail(e) 1169 except FunctionException, e: 1170 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1171 self.assertTrue(e.getRetval() == result, msg=msg) 1172 1173 msg = "record.value: %s, test: %s" % (record.value, test) 1174 self.assertTrue(test == record.value, msg=msg)
1175
1176 - def _saveList(self, path, result=Return.NORMAL):
1177 """ 1178 Execute the C{saveList} method, asserts that there are no 1179 C{APIException} or C{FunctionException} exceptions, and asserts that 1180 the return code is correct. 1181 1182 @param path: The full path to the data file. 1183 @type path: C{str} 1184 @keyword result: The expected value, the default is C{Return.NORMAL}. 1185 @type result: C{Return} 1186 @return: C{None} 1187 """ 1188 try: 1189 retval = self._dll.saveList(path) 1190 except APIException, e: 1191 self.fail(e) 1192 except FunctionException, e: 1193 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1194 self.assertTrue(e.getRetval() == result, msg=msg)
1195
1196 - def _loadList(self, path, pFun=None, result=Return.NORMAL):
1197 """ 1198 Execute the C{loadList} method, asserts that there are no 1199 C{APIException} or C{FunctionException} exceptions, and asserts that 1200 the return code is correct. 1201 1202 @param path: The full path to the data file. 1203 @type path: C{str} 1204 @keyword pFun: An optional compare function, the default is C{None}. 1205 @type pFun: C{ctypes CFUNCTYPE} 1206 @keyword result: The expected value, the default is C{Return.NORMAL}. 1207 @type result: C{Return} 1208 @return: C{None} 1209 """ 1210 try: 1211 retval = self._dll.loadList(path, pFun=pFun) 1212 except APIException, e: 1213 self.fail(e) 1214 except FunctionException, e: 1215 msg = "Return.%s: %s" % Return.getMessage(e.getRetval()) 1216 self.assertTrue(e.getRetval() == result, msg=msg)
1217 1218 1219 if __name__ == '__main__': 1220 unittest.main() 1221