DEFINE CLASS wwUtilsTests as FxuTestCase OF FxuTestCase.prg


*** SETUP AND CONFIGURATION *** 

************************************************************************
*  Setup
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION Setup()

	*** Make sure libraries are loaded
	DO wconnect
ENDFUNC
*   Setup

************************************************************************
*  TearDown
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION TearDown()

ENDFUNC
*   TearDown


************************************************************************
*  IsNumber
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION IsNumber()

THIS.AssertTrue( IsNumber(10) )
THIS.AssertFalse( isNumber("a"),"Not a number test not false" )
THIS.AssertTrue( isNumber("10") )
THIS.AssertTrue(  isNumber("101"))
THIS.AssertFalse(  isNumber("101a"),"Mixed number and text test not false" )
THIS.AssertTrue(  isNumber("101.11") )

ENDFUNC
*   IsNumber


************************************************************************
*  CopyObjectPropertiesSingleLevelEmpty
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION CopyObjectPropertiesSingleLevelEmpty()

loSrc = CREATEOBJECT("Empty")

ADDPROPERTY(loSrc,"Name","Rick")
ADDPROPERTY(loSrc,"Company","West Wind")
ADDPROPERTY(loSrc,"Entered",DATETIME() - 100)

loTrg = CREATEOBJECT("Empty")

ADDPROPERTY(loTrg,"Name","")
ADDPROPERTY(loTrg,"Company","")
ADDPROPERTY(loTrg,"Entered",DATE()-1000)


CopyObjectProperties(loSrc,loTrg,2,.f.,"")

THIS.AssertTrue(loSrc.Name = loTrg.Name)
THIS.AssertTrue(loSrc.Entered = loTrg.Entered)

ENDFUNC
*   CopyObjectPropertiesSingleLevelEmpty1

************************************************************************
*  CopyObjectPropertiesHierarchyEmpty
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION CopyObjectPropertiesHierarchyEmpty()

loSrc = CREATEOBJECT("Empty")

ADDPROPERTY(loSrc,"Name","Rick")
ADDPROPERTY(loSrc,"Company","West Wind")
ADDPROPERTY(loSrc,"Entered",DATETIME() - 100)

loSrc2 = CREATEOBJECT("EMPTY")
ADDPROPERTY(loSrc2,"Street","32 Kaiea Place")
ADDPROPERTY(loSrc2,"Number",10)
ADDPROPERTY(loSrc2,"Zip","97031")
ADDPROPERTY(loSrc2,"Entered",DATE())

ADDPROPERTY(loSrc,"Address",loSrc2)

laItems = ADDPROPERTY(loSrc,"Items[3]",.F.)
loSrc.Items[1] = "Rick"
loSrc.Items[2] = "Strahl"
loSrc.Items[3] = "West Wind"

ADDPROPERTY(loSrc,"Addresses",CREATEOBJECT("Collection"))
loSrc.Addresses.Add(loSrc.Address)
loSrc.Addresses.Add("32 Kaiea Place")


loTrg = CREATEOBJECT("Empty")

ADDPROPERTY(loTrg,"Name","")
ADDPROPERTY(loTrg,"Company","")
ADDPROPERTY(loTrg,"Entered",DATE()-1000)


loTrg2 = CREATEOBJECT("EMPTY")
ADDPROPERTY(loTrg2,"Street","")
ADDPROPERTY(loTrg2,"Number",0)
ADDPROPERTY(loTrg2,"Zip","")
ADDPROPERTY(loTrg2,"Entered",DATE()-1000)

ADDPROPERTY(loTrg,"Address",loTrg2)
ADDPROPERTY(loTrg,"Addresses",NULL)

ADDPROPERTY(loTrg,"Items[1]",.F.)

CopyObjectProperties(loSrc,loTrg,2,.f.,"")

THIS.AssertTrue(loSrc.Name = loTrg.Name)
THIS.AssertTrue(loSrc.Entered = loTrg.Entered)

THIS.AssertTrue(loSrc.Address.Street = loTrg.Address.Street)
THIS.AssertTrue(loSrc.Address.Entered = loTrg.Address.Entered)
THIS.AssertTrue(loSrc.Address.Number = loTrg.Address.Number)

this.AssertTrue(loSrc.Items[2] = loTrg.Items[2])

this.AssertTrue(loSrc.Addresses[1].Street == loTrg.Addresses[1].Street)
this.AssertTrue(loSrc.Addresses[2] == loTrg.Addresses[2])

this.MessageOut(loTrg.Address.Street)
this.MessageOut(TRANSFORM(loTrg.Address.Number))
this.MessageOut(loTrg.Addresses[2])
ENDFUNC
*   CopyObjectPropertiesHierarchyEmpty


************************************************************************
*  FromIsoDateToIsoDate
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION FromIsoDateToIsoDate()

ldOrigDate = DATETIME()
this.MessageOut("Orig date: " + TRANSFORM(ldOrigDate) )
lcDate = ToIsoDateString( ldOrigDate, .T. )
lcDate = lcDate + "Z"

this.MessageOut( "Iso Date: " + lcDate)
ldDate = FromIsoDateString( lcDate )

this.MessageOut( "From ISO Date: " + TRANSFORM(ldDate))

this.AssertTrue( ldDate == ldOrigDate,"Data conversion does not match")

ENDFUNC
*   FromIsoDateToIsoDate


************************************************************************
*  HumanizeDate
****************************************
***  Function:
***    Assume:
***      Pass:
***    Return:
************************************************************************
FUNCTION HumanizeDate()

this.MessageOut("10 seconds: " +   humanizedDate(DATETIME() - 10 ))
this.MessageOut("1 minute: " +   humanizedDate(DATETIME() - 60 ))
this.MessageOut("2 minutes: " +   humanizedDate(DATETIME() - 120 ))
this.MessageOut("59 minutes: " +   humanizedDate(DATETIME() - 59 * 60))
this.MessageOut("1 hour: " +   humanizedDate(DATETIME() - 60 * 60) )
this.MessageOut("1 10 hour: " +   humanizedDate(DATETIME() - 60 * 60 - 600) )
this.MessageOut("2 hours: " +   humanizedDate(DATETIME() - 7300 ))
this.MessageOut("1 day: " +   humanizedDate(DATETIME() - 88300 ))


ENDFUNC
*   HumanizeDate



ENDDEFINE
