#!/usr/bin/env python
###########################################################################
# guidedogtest.py - description                                           #
# ------------------------------                                          #
# begin     : Sun Nov 19 2006                                             #
# copyright : (C) 2006 by Simon Edwards                                   #
# email     : simon@simonzone.com                                         #
#                                                                         #
###########################################################################
#                                                                         #
#   This program is free software; you can redistribute it and/or modify  #
#   it under the terms of the GNU General Public License as published by  #
#   the Free Software Foundation; either version 2 of the License, or     #
#   (at your option) any later version.                                   #
#                                                                         #
###########################################################################

import unittest
import guidedog
from PyQt4 import QtCore
from PyQt4 import QtGui

class TestAddressValidator(unittest.TestCase):

    def setUp(self):
        self.validator = guidedog.AddressValidator()
    
    def validate(self,source,result):
        (rc,pos) = self.validator.validate(QtCore.QString(source),0)
        self.assert_(rc==result)
    
    def test1Check(self):
        self.validate("www.simonzone.com",QtGui.QValidator.Acceptable)
        
    def test2Check(self):
        self.validate("192.168.1.1",QtGui.QValidator.Acceptable)
        
    def test3Check(self):
        self.validate("192.168.1.1/255.255.255.0",QtGui.QValidator.Acceptable)
        
    def test4Check(self):
        self.validate("www.simon-zone.com",QtGui.QValidator.Acceptable)
        
    def test5Check(self):
        self.validate("192.168.1.1/24",QtGui.QValidator.Acceptable)
        
    def test1Intermediate(self):
        self.validate("192.168.",QtGui.QValidator.Intermediate)
        
    def test2Intermediate(self):
        self.validate("www",QtGui.QValidator.Intermediate)

    def test3Intermediate(self):
        self.validate("192.168.1.1/24.",QtGui.QValidator.Intermediate)
        
    def test4Intermediate(self):
        self.validate("192.168.1.256",QtGui.QValidator.Intermediate)
        
    def test5Intermediate(self):
        self.validate("192.168.1.1/256.0.0.0",QtGui.QValidator.Intermediate)
        
    def test6Intermediate(self):
        self.validate("",QtGui.QValidator.Intermediate)
        
    def test7Intermediate(self):
        self.validate("www.-e.com",QtGui.QValidator.Intermediate)
        
    def test8Intermediate(self):
        self.validate("www.123abc.com",QtGui.QValidator.Intermediate)
        
    def test1Invalid(self):
        self.validate("abc@efgh",QtGui.QValidator.Invalid)
   
    def test1Fixup(self):
        src = QtCore.QString("")
        self.validator.fixup(src)
        self.assert_(src=="0.0.0.0")

    def test2Fixup(self):
        src = QtCore.QString("www.simonzone@com")
        self.validator.fixup(src)
        self.assert_(src=="www.simonzonecom")

    def test3Fixup(self):
        src = QtCore.QString("192.168.256.1")
        self.validator.fixup(src)
        self.assert_(src=="192.168.255.1")
        
class TestIPValidator(unittest.TestCase):

    def setUp(self):
        self.validator = guidedog.IPValidator()
    
    def validate(self,source,result):
        (rc,pos) = self.validator.validate(QtCore.QString(source),0)
        self.assert_(rc==result)
        
    def test1Check(self):
        self.validate("192.168.1.1",QtGui.QValidator.Acceptable)
        
    def test2Check(self):
        self.validate("192.168.1.1/255.255.255.0",QtGui.QValidator.Acceptable)
        
    def test5Check(self):
        self.validate("192.168.1.1/24",QtGui.QValidator.Acceptable)
        
    def test1Intermediate(self):
        self.validate("192.168.",QtGui.QValidator.Intermediate)

    def test2Intermediate(self):
        self.validate("192.168.1.1/24.",QtGui.QValidator.Intermediate)
        
    def test3Intermediate(self):
        self.validate("192.168.1.256",QtGui.QValidator.Intermediate)
        
    def test4Intermediate(self):
        self.validate("192.168.1.1/256.0.0.0",QtGui.QValidator.Intermediate)
        
    def test5Intermediate(self):
        self.validate("",QtGui.QValidator.Intermediate)
        
    def test1Invalid(self):
        self.validate("12.3@.45.6",QtGui.QValidator.Invalid)
   
    def test1Fixup(self):
        src = QtCore.QString("")
        self.validator.fixup(src)
        self.assert_(src=="0.0.0.0")

    def test2Fixup(self):
        src = QtCore.QString("192.168.256.1")
        self.validator.fixup(src)
        self.assert_(src=="192.168.255.1")
        
if __name__ == '__main__':
    unittest.main()
