###############################################################################
# File:        UnitTest_CmdEditor.py
# Appointment: GUI unittest for command editor 
# Project:     GalaxyU
# Author:      AR
# History:
# 21.03.2016 Created
###############################################################################
import unittest
import sys
sys.path.append("../")

from ctypes import *

import guApp
import guCmdEditor
import guObjects
import guReport
import UnitTest_guReport

import zx


###############################################################################
class TestCmdEditor(unittest.TestCase):
    TestEmail = "myemail@o2.co.uk"
    TestPassword = "123456"

    #--------------------------------------------------------------------------
    @classmethod
    def setUpClass(cls):
        cls.__report = guApp.Application.GetReport()
        cls.__report.Load(c_char_p(UnitTest_guReport.REPORT_PATH))
        guApp.Application.Config.SetItem(\
            guApp.Application.GetCredentialsCfgPath() + "Email", cls.TestEmail)
        guApp.Application.Config.SetItem(\
            guApp.Application.GetCredentialsCfgPath() + "Password", cls.TestPassword)

    #///////////////////////////////////////////////////////////////////////////
    def __CheckText(self, aText, aTo, aWhom, aSender = None, aSenderStr = None):
        lines = aText.split("\n")
        print lines
        delta = 2 if aSender is not None else 0
        self.assertEqual(10 + delta, len(lines))
        self.assertEqual("#message", lines[0])
        self.assertEqual("login: " + self.TestEmail + "/" + self.TestPassword, lines[1])
        self.assertEqual("to: " + aTo, lines[2])
        self.assertEqual("Greetings, " + aWhom, lines[4])
        if aSender is not None:
            self.assertEqual("Kind Regards,", lines[8])
            self.assertEqual(aSenderStr, lines[9])
        self.assertEqual("#end", lines[8 + delta])

    #--------------------------------------------------------------------------
    def test_GetTextMessageTo_All(self):
        self.__CheckText(guCmdEditor.GetTextMessageTo(None), "All", "All")

        sender = guObjects.CRuler(None, "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(None, sender), "All", "All", sender, "GM")

        sender = guObjects.CRuler("", "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(None, sender), "All", "All", sender, "Henry")


    #--------------------------------------------------------------------------
    def test_GetTextMessageTo_GM(self):
        receiver = guObjects.CRuler(None, "Henry", "Baron")
        self.__CheckText(guCmdEditor.GetTextMessageTo(receiver), "GM", "GM")

        sender = guObjects.CRuler(None, "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(receiver, sender), "GM", "GM", sender, "GM")

        sender = guObjects.CRuler("", "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(receiver,sender), "GM", "GM", sender, "Henry")


    #--------------------------------------------------------------------------
    def test_GetTextMessageTo_Nation(self):
        receiver = guObjects.CRuler("Antares", "Henry", "Baron")
        self.__CheckText(guCmdEditor.GetTextMessageTo(receiver), "Antares", "Baron Henry")

        sender = guObjects.CRuler(None, "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(receiver, sender),
            "Antares", "Baron Henry", sender, "GM")

        sender = guObjects.CRuler("", "Henry", "Baron")
        self.__CheckText(\
            guCmdEditor.GetTextMessageTo(receiver,sender),
            "Antares", "Baron Henry", sender, "Henry")
        

################################################################################
if __name__ == "__main__":
    unittest.main()
