diff options
author | Georgy Redkozubov <georgy.redkozubov@linaro.org> | 2012-05-23 11:11:02 +0400 |
---|---|---|
committer | Georgy Redkozubov <georgy.redkozubov@linaro.org> | 2012-05-23 11:11:02 +0400 |
commit | e446473285ab309bc48469d418855a156bcc6489 (patch) | |
tree | ff9ac96b7ab0fc53c6ba0301b6b4c4d0097186a4 /tests | |
parent | 6effe13d2e956022d1fa797a1dcb422c68d97285 (diff) |
Added PHP unit tests for BuildInfo class
Diffstat (limited to 'tests')
-rw-r--r-- | tests/BUILD-INFO.txt | 17 | ||||
-rw-r--r-- | tests/BuildInfoTest.php | 122 | ||||
-rw-r--r-- | tests/__init__.py | 1 | ||||
-rw-r--r-- | tests/test_build_info.py | 40 |
4 files changed, 180 insertions, 0 deletions
diff --git a/tests/BUILD-INFO.txt b/tests/BUILD-INFO.txt new file mode 100644 index 0000000..113942e --- /dev/null +++ b/tests/BUILD-INFO.txt @@ -0,0 +1,17 @@ +Format-Version: 0.1 +Build-Name: landing-snowball +Theme: stericsson +License-Type: open +OpenID-Launchpad-Teams: linaro,non-linaro +Collect-User-Data: yes +License-Text: <p>IMPORTANT — PLEASE READ THE FOLLOWING AGREEMENT CAREFULLY.</p> +<p> + THIS IS A LEGALLY BINDING AGREEMENT BETWEEN YOU, an individual or a + legal entity, (“LICENSEE”) AND SAMSUNG ELECTRONICS CO., + LTD. (“SAMSUNG”). BY CLICKING THE "ACCEPT" BUTTON, OR BY DOWNLOADING OR + INSTALLING OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY THE + TERMS OF THIS AGREEMENT. IF YOU DO NOT AGREE TO THE TERMS OF THIS + AGREEMENT OR ARE NOT AUTHORISED TO ACCEPT AND AGREE TO THE TERMS OF THE + AGREEMENT ON BEHALF OF YOUR LEGAL ENTITY, DO NOT DOWNLOAD, INSTALL OR + OTHERWISE USE THE SOFTWARE. +</p> diff --git a/tests/BuildInfoTest.php b/tests/BuildInfoTest.php new file mode 100644 index 0000000..550c373 --- /dev/null +++ b/tests/BuildInfoTest.php @@ -0,0 +1,122 @@ +<?php + +require_once("licenses/BuildInfo.php"); + +class BuildInfoTest extends PHPUnit_Framework_TestCase +{ + + private $temp_filename; + private $good_bi; + private $bi; + + public function __construct() + { + $this->good_bi = new BuildInfo(); + $this->good_bi->readFile("tests/BUILD-INFO.txt"); + $this->temp_filename = tempnam(sys_get_temp_dir(), "build-info"); + $this->bi = new BuildInfo(); + $this->bi->readFile($this->temp_filename); + } + + /** + * Running readFile on a directory path returns false. + */ + public function test_readFile_nonFile() + { + $this->assertFalse(BuildInfo::readFile(dirname(__FILE__))); + } + + /** + * Running readFile on a nonexistent file returns false. + */ + public function test_readFile_nonexistentFile() + { + $this->assertFalse(BuildInfo::readFile("nonexistent.file")); + } + + /** + * Running readFile on a regular file returns true. + */ + public function test_readFile_file() + { + $bi = new BuildInfo(); + $this->assertTrue($bi->readFile(__FILE__)); + } + + /** + * Running 'get' functions on an empty fields returns false. + */ + public function test_getFormatVersion_empty() + { + $this->assertFalse($this->bi->getFormatVersion()); + } + + /** + * Running 'get' functions on non-empty fields returns string value. + */ + public function test_getFormatVersion() + { + $this->assertInternalType('string', $this->good_bi->getFormatVersion()); + } + + public function test_getBuildName_empty() + { + $this->assertFalse($this->bi->getBuildName()); + } + + public function test_getBuildName() + { + $this->assertInternalType('string', $this->good_bi->getBuildName()); + } + + public function test_getTheme_empty() + { + $this->assertFalse($this->bi->getTheme()); + } + + public function test_getTheme() + { + $this->assertInternalType('string', $this->good_bi->getTheme()); + } + + public function test_getLicenseType_empty() + { + $this->assertFalse($this->bi->getLicenseType()); + } + + public function test_getLicenseType() + { + $this->assertInternalType('string', $this->good_bi->getLicenseType()); + } + + public function test_getCollectUserData_empty() + { + $this->assertFalse($this->bi->getCollectUserData()); + } + + public function test_getCollectUserData() + { + $this->assertInternalType('string', $this->good_bi->getCollectUserData()); + } + + public function test_getLaunchpadTeams_empty() + { + $this->assertFalse($this->bi->getLaunchpadTeams()); + } + + public function test_getLaunchpadTeams() + { + $this->assertInternalType('string', $this->good_bi->getLaunchpadTeams()); + } + + public function test_getLicenseText_empty() + { + $this->assertFalse($this->bi->getLicenseText()); + } + + public function test_getLicenseText() + { + $this->assertInternalType('string', $this->good_bi->getLicenseText()); + } +} +?> diff --git a/tests/__init__.py b/tests/__init__.py index 56f6d60..bbfd694 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -6,6 +6,7 @@ def test_suite(): 'tests.test_click_through_license.TestLicense', 'tests.test_publish_to_snapshots.TestSnapshotsPublisher', 'tests.test_php_unit.PhpUnitTest', + 'tests.test_build_info.BuildInfoTest', ] loader = unittest.TestLoader() suite = loader.loadTestsFromNames(module_names) diff --git a/tests/test_build_info.py b/tests/test_build_info.py new file mode 100644 index 0000000..759bd9f --- /dev/null +++ b/tests/test_build_info.py @@ -0,0 +1,40 @@ +import os +import tempfile +import subprocess +import xml.etree.ElementTree + +from testtools import TestCase +from testtools.matchers import Equals +from testtools.matchers import AllMatch + +from tests.test_click_through_license import CommandNotFoundException + + +class BuildInfoTest(TestCase): + '''Tests for executing the BuildInfo PHP Unit tests''' + + def setUp(self): + super(BuildInfoTest, self).setUp() + + self.build_info_xml_path = tempfile.mkstemp()[1] + if subprocess.Popen(['phpunit', '--log-junit', + self.build_info_xml_path, 'tests/BuildInfoTest'], + stdout=open('/dev/null', 'w'), + stderr=subprocess.STDOUT).wait(): + raise CommandNotFoundException("phpunit command not found. Please " + "install phpunit package and rerun tests.") + self.build_info_xml_data = xml.etree.ElementTree.parse(self.build_info_xml_path) + + def tearDown(self): + super(BuildInfoTest, self).tearDown() + if os.path.exists(self.build_info_xml_path): + os.unlink(self.build_info_xml_path) + + def test_run_buildinfo_tests(self): + self.assertThat( + [ + self.build_info_xml_data.getroot()[0].attrib['failures'], + self.build_info_xml_data.getroot()[0].attrib['errors'] + ], + AllMatch(Equals("0")) + ) |