Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[r3046]: test / releases / 3.1.2 / tests / oorexxunit / ooRexx / base / class / ooRexx.Base.Class.Properties.testUnit Maximize Restore History

Download this file

ooRexx.Base.Class.Properties.testUnit    449 lines (347 with data), 14.9 kB

#!/usr/bin/rexx
/*
   name:             ooRexx.Base.Class.Properties.testUnit
   author:           Rony G. Flatscher
   date:             2007-03-21
   version:          1.0.0

-- line commented lines are ignored, when building the directory of infos from this header
   changed:          ---

   languageLevel:    6.0.1
   purpose:          Test the methods of the class CircularQueue.
   remark:           ---

   license:          CPL 1.0 (Common Public License v1.0, see below)
   link:

// category needs not to be numbered, importance is given by position (1=most important)
   category:         ooRexx
   category:         Base
   category:         Class
   category:         Properties
*/
/*----------------------------------------------------------------------------*/
/*                                                                            */
/* Copyright (c) 2007 Rexx Language Association. All rights reserved.         */
/*                                                                            */
/* This program and the accompanying materials are made available under       */
/* the terms of the Common Public License v1.0 which accompanies this         */
/* distribution. A copy is also available at the following address:           */
/* http://www.oorexx.org/license.html                                         */
/*                                                                            */
/* Redistribution and use in source and binary forms, with or                 */
/* without modification, are permitted provided that the following            */
/* conditions are met:                                                        */
/*                                                                            */
/* Redistributions of source code must retain the above copyright             */
/* notice, this list of conditions and the following disclaimer.              */
/* Redistributions in binary form must reproduce the above copyright          */
/* notice, this list of conditions and the following disclaimer in            */
/* the documentation and/or other materials provided with the distribution.   */
/*                                                                            */
/* Neither the name of Rexx Language Association nor the names                */
/* of its contributors may be used to endorse or promote products             */
/* derived from this software without specific prior written permission.      */
/*                                                                            */
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS        */
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT          */
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS          */
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,      */
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED   */
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,        */
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING    */
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS         */
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.               */
/*                                                                            */
/*----------------------------------------------------------------------------*/


testUnitClass=.ooRexx.Base.Class.Properties.TestUnit  -- change accordingly
-------------------------------------------------------------------------------------------
-- ===> adapt the "testUnitList" to your testCase classes; each element in the list is <===
-- ===> an array object, the first element containing the testCase class object, the   <===
-- ===> second element is a list of test method names which are regarded to be         <===
-- ===> mandatory (if the list remains empty all test methods are mandatory)           <===

   /* list of array objects, each containing the testUnit class object and an
      optional list of mandatory test case methods name                       */
mandatoryTestMethods=.list~new   -- no mandatory tests for this testCase class
testUnitList=.list~of( .array~of(.ooRexx.Base.Class.Properties.testUnit,  mandatoryTestMethods) )


-------------------------------------------------------------------------------------------
-- ===> the following code needs not to be individualized                              <===

   -- read top comment, containing infos about this program
arrLines=.array~new
do i=1 to 150 until arrLines[i]="*/"
   arrLines[i]=sourceline(i)
end
      -- supply information for the testClass(es) in this file; the class attribute
      -- "TestCaseInfo" (a directory object, index points to a queue) will store
      -- the parsed infos
aTestUnitClass=testUnitList~at(testUnitList~first)[1] -- get first testClass

   -- will parse the array lines and store result in class object
call makeDirTestInfo aTestUnitClass, arrLines
tmpDir=aTestUnitClass~TestCaseInfo
parse source s   -- op_sys invocationType fullPathToThisFile
tmpDir~setentry("test_Case-source", s)

   -- now add this directory to other testCase classes, if any left
do arr over testUnitList
   if arr[1]=aTestUnitClass then iterate  -- already handled
   arr[1]~TestCaseInfo=tmpDir             -- save info in class object
end

-- if this file is CALLed or REQUIRED then define an entry "bRunTestLocally" in .local
-- and set it to .false; this way the independent local invocation of the tests is inhibited
if .local~hasentry("bRunTestsLocally")=.false then
   .local~bRunTestsLocally=.true -- if this file is executed directly, then run tests for debugging

if .bRunTestsLocally=.true then  -- run ALL tests in this test unit
do
   ts=.testSuite~new             -- create a testSuite
   do arr over testUnitList
      -- create a testSuite for the given test case class, use all its testmethods
      ts~addTest( .testSuite~new(arr[1]))
   end
   -- testResult=.testSuite~new(testUnitClass)~run
   testResult=ts~run       -- now run all the tests

   call simpleDumpTestResults testResult
end

   /* return list of array objects containing test case classes and
      optionally list of mandatory test methods                      */
return testUnitList



::requires ooRexxUnit.cls     -- load the ooRexxUnit classes


::class "testData"
::method init class
  expose dirData files

  dirData=.directory~new
  dirData["ENTRY1"]="VALUE1"
  dirData["entry2"]="value2"

  files=.array~of("testProperty1.prop", "testProperty2.prop")


::method dirData  attribute class
::method files    attribute class

   -- class named exactly like file
::class "ooRexx.Base.Class.Properties.TestUnit" subclass TestCase public

   -- create "testProperties1.prop", make sure
::method internal_setup
  self~internal_tearDown         -- make sure no leftover files exist
  file=.testData~files[1]        -- get file name to use
  dir =.testData~dirData         -- get directory data
  arr =dir~makearray
  call lineout file, "-- a comment, created" date("S") time("L")
  call lineout file, ""

  call lineout file, "-- no blanks inserted:"
  call lineout file, arr[1]"="dir[arr[1]]
  call lineout file, ""

  call lineout file, "-- blanks around key and leading blanks in value inserted!"
  call lineout file, "  " arr[2]"   ="dir[arr[2]]
  call lineout file, ""
  call lineout file  -- close file
  call lineout file  -- close file


::method internal_tearDown
  do file over .testData~files
     if stream(file, "C", "QUERY EXISTS")<>"" then -- file exists, remove it
     do
        call sysFileDelete file
     end
  end


   -- test arguments ---------------------------------------------

::method "test_LOAD_ARG_1"
   self~expectSyntax(93.903)     -- omitted argument
   .Properties~load

::method "test_LOAD_ARG_2"
   self~expectSyntax(93.902)     -- too many arguments
   .Properties~load(1,2)

::method "test_SAVE_ARG_1"
   self~expectSyntax(93.903)     -- omitted argument
   .Properties~new~SAVE

::method "test_SAVE_ARG_2"
   self~expectSyntax(93.902)     -- too many arguments
   .Properties~new~SAVE(1,2)

   -- SETPROPERTY
::method "test_SETPROPERTY_ERR_01"
   self~expectSyntax(93.902)
   .properties~new~setProperty(1,2,3)

::method "test_SETPROPERTY_ERR_02"
   self~expectSyntax(93.903)
   .properties~new~setProperty( ,2)

::method "test_SETPROPERTY_ERR_03"
   self~expectSyntax(93.903)
   .properties~new~setProperty(1 , )

::method "test_SETPROPERTY_ERR_04"
   self~expectSyntax(93.938)
   .properties~new~setProperty(1 , .nil)


   -- GETPROPERTY
::method "test_GETPROPERTY_ERR_01"
   self~expectSyntax(93.902)
   .properties~new~GETProperty(1, 2, 3)

::method "test_GETPROPERTY_ERR_02"
   self~expectSyntax(93.903)
   .properties~new~GETProperty( )

::method "test_GETPROPERTY_DEFAULT_VALUE"
   val="aha"
   self~assertEquals("subtest_01", val, .properties~new~getProperty(x, val))



   -- SETWHOLE
::method "test_SETWHOLE_ERR_01"
   self~expectSyntax(93.903)
   .properties~new~setWHOLE()

::method "test_SETWHOLE_ERR_02"
   self~expectSyntax(93.905)
   .properties~new~setWHOLE(1, "aha")


   -- GETWHOLE
::method "test_GETWHOLE_ERR_01"
   self~expectSyntax(26.901)
   key="a"
   val="b"
   p=.properties~new~~setProperty(key, val)
   p~getWHOLE(key)

::method "test_GETWHOLE_DEFAULT"
   p=.properties~new
   key="a"
   val=1
   self~assertEquals("subtest_01", val, p~getWHOLE(key, val))
   val=0
   self~assertEquals("subtest_02", val, p~getWHOLE(key, val))


   -- SETLOGICAL
::method "test_SETLOGICAL_ERR_01"
   self~expectSyntax(93.903)
   .properties~new~setLOGICAL()

::method "test_SETLOGICAL_ERR_02"
   self~expectSyntax(34.901)
   .properties~new~setLOGICAL(1, "aha")


   -- GETLOGICAL
::method "test_GETLOGICAL_ERR_01"
   -- self~expectSyntax(26.901)
   self~expectSyntax(34.904)
   key="a"
   val="b"
   p=.properties~new~~setProperty(key, val)
   p~getLOGICAL(key)

::method "test_GETLOGICAL_DEFAULT"
   p=.properties~new
   key="a"
   val=1
   self~assertEquals("subtest_01", val, p~getLOGICAL(key, val))
   val=0
   self~assertEquals("subtest_02", val, p~getLOGICAL(key, val))



   -- []=
::method "test_[]=_ERR_01"
   self~expectSyntax(93.902)
   .properties~new~"[]="(1,2,3)

::method "test_[]=_ERR_02"
   self~expectSyntax(93.903)
   .properties~new~"[]="(,2)

::method "test_[]=_ERR_03"
   self~expectSyntax(93.903)
   .properties~new~"[]="(1)

::method "test_[]=_ERR_04"
   self~expectSyntax(93.938)
   .properties~new~"[]="(1, .nil)


   -- PUT
::method "test_PUT_ERR_01"
   self~expectSyntax(93.902)
   .properties~new~"PUT"(1,2,3)

::method "test_PUT_ERR_02"
   self~expectSyntax(93.903)
   .properties~new~"PUT"(,2)

::method "test_PUT_ERR_03"
   self~expectSyntax(93.903)
   .properties~new~"PUT"(1)

::method "test_PUT_ERR_04"
   self~expectSyntax(93.938)
   .properties~new~"PUT"(1, .nil)




::method "test_load_via_classmethod"
  self~internal_setup
  str=.stream~new(.testData~files[1])
  props=.properties~load(str)
  self~assertEquals("subtest_01 - using class method 'load'", 2, props~items)

  s=.testData~dirData~supplier   -- were the entries retrieved correctly?
  n=1
  do while s~available
     n=n+1
     self~assertTrue("subtest_"right(n,2,0), props~hasIndex(s~index))
     self~assertSame("subtest_"right(n,2,0), s~item, props[s~index])
     s~next
  end
  str~close
  self~internal_tearDown



::method "test_load_and_save_via_instanceMethod_using_Stream_Objects"
  self~internal_setup

  str=.stream~new(.testData~files[1])
  props=.properties~new
  props~load(str)
  self~assertEquals("subtest_01 - using class method 'load'", 2, props~items)

  s=.testData~dirData~supplier   -- were the entries retrieved correctly?
  n=1
  do while s~available
     n=n+1
     self~assertTrue("props-subtest_"right(n,2,0), props~hasIndex(s~index))
     self~assertSame("props-subtest_"right(n,2,0), s~item, props[s~index])
     s~next
  end
  str~close

   -- save properties with property file
  str2=.stream~new(.testData~files[2])~~open("REPLACE")
  props~save(str2)
  str2~close

  str2=.stream~new(.testData~files[2])
  props2=.properties~new~~load(str2)
  str2~close

  n=0
  do idx over props
     n=n+1
     val1=props[idx]
     val2=props2[idx]
     self~assertEquals("props2-subtest_"right(n,2,0), val1, val2)
  end
  self~internal_tearDown


::method "test_load_and_save_via_instanceMethod_using_String_to_contain_name"
  self~internal_setup

  str=.testData~files[1]
  props=.properties~new
  props~load(str)
  self~assertEquals("subtest_01 - using class method 'load'", 2, props~items)

  s=.testData~dirData~supplier   -- were the entries retrieved correctly?
  n=1
  do while s~available
     n=n+1
     self~assertTrue("props-subtest_"right(n,2,0), props~hasIndex(s~index))
     self~assertSame("props-subtest_"right(n,2,0), s~item, props[s~index])
     s~next
  end

   -- save properties with property file
  str2=.testData~files[2]
  props~save(str2)
  props2=.properties~new~~load(str2)

  n=0
  do idx over props
     n=n+1
     val1=props[idx]
     val2=props2[idx]
     self~assertEquals("props2-subtest_"right(n,2,0), val1, val2)
  end
  self~internal_tearDown



::method "test_get_and_set_properties"
  props=.properties~new

  key="rgf"
  val=1
  logVal="true"
  props~setProperty(key, val)
  self~assertEquals("subtest_01a", val,    props~getProperty(key)  )
  self~assertEquals("subtest_02a", val,    props~getWhole(key)     )

  props~setLogical(key, val)
  self~assertEquals("subtest_03a", logVal, props~getProperty(key)  )
  self~assertEquals("subtest_04a", val,    props~getLogical(key)   )

  props~setWhole(key, val)
  self~assertEquals("subtest_05a", val,    props~getProperty(key)  )
  self~assertEquals("subtest_06a", val,    props~getWhole(key)     )

  props~setLogical(key, val)
  self~assertEquals("subtest_07a", logVal, props~getProperty(key)  )
  self~assertEquals("subtest_08a", val,    props~getLogical(key)   )


  key="rgf"
  val=0
  logVal="false"
  props~setProperty(key, val)
  self~assertEquals("subtest_01b", val,    props~getProperty(key)  )
  self~assertEquals("subtest_02b", val,    props~getWhole(key)     )

  props~setLogical(key, val)
  self~assertEquals("subtest_03b", logVal, props~getProperty(key)  )
  self~assertEquals("subtest_04b", val,    props~getLogical(key)   )

  props~setWhole(key, val)
  self~assertEquals("subtest_05b", val,    props~getProperty(key)  )
  self~assertEquals("subtest_06b", val,    props~getWhole(key)     )

  props~setLogical(key, val)
  self~assertEquals("subtest_07b", logVal, props~getProperty(key)  )
  self~assertEquals("subtest_08b", val,    props~getLogical(key)   )