|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 import unittest, os, shutil |
|
18 |
|
19 import __init__ |
|
20 from genconfmlplugin import genconfmlplugin |
|
21 from cone.public import exceptions,plugin,api |
|
22 from cone.storage import filestorage |
|
23 from cone.confml import implml |
|
24 |
|
25 try: |
|
26 from cElementTree import ElementTree |
|
27 except ImportError: |
|
28 try: |
|
29 from elementtree import ElementTree |
|
30 except ImportError: |
|
31 try: |
|
32 from xml.etree import cElementTree as ElementTree |
|
33 except ImportError: |
|
34 from xml.etree import ElementTree |
|
35 |
|
36 |
|
37 # Hardcoded value of testdata folder that must be under the current working dir |
|
38 ROOT_PATH = os.path.dirname(os.path.abspath(__file__)) |
|
39 testdata = os.path.join(ROOT_PATH,'project') |
|
40 |
|
41 invalidxml_string = '<file xmlns="http://www.s60.com/xml/genconfml/1">' |
|
42 genconfgml_string = \ |
|
43 '<file xmlns="http://www.s60.com/xml/genconfml/1" name="Setting/Data.xml" target="output">'\ |
|
44 ' <setting ref="Setting/Settings"/>'\ |
|
45 ' <setting ref="Setting/ContentSettings"/>'\ |
|
46 ' <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xi="http://www.w3.org/2001/xinclude">'\ |
|
47 ' <xsl:output method="xml" indent="yes" encoding="UTF-8"/>'\ |
|
48 ' <xsl:template match="configuration/data">'\ |
|
49 ' <Variant>'\ |
|
50 ' <xsl:copy-of select="Setting/Settings"/>'\ |
|
51 ' <xsl:copy-of select="Setting/ContentSettings"/>'\ |
|
52 ' </Variant>'\ |
|
53 ' </xsl:template>'\ |
|
54 ' </xsl:stylesheet>'\ |
|
55 '</file>' |
|
56 |
|
57 |
|
58 |
|
59 class TestGenconfmlPlugin(unittest.TestCase): |
|
60 def setUp(self): |
|
61 self.curdir = os.getcwd() |
|
62 self.output = os.path.join(ROOT_PATH, 'temp/output') |
|
63 |
|
64 def test_example_parse_and_generate_prj2(self): |
|
65 fs = filestorage.FileStorage(testdata) |
|
66 p = api.Project(fs) |
|
67 config = p.get_configuration('root1.confml') |
|
68 impls = plugin.get_impl_set(config,'\.gcfml$') |
|
69 impls.output = self.output |
|
70 impl = impls.get_implementations_by_file('Layer1/implml/feature1.gcfml')[0] |
|
71 impls.generate() |
|
72 |
|
73 def test_predefined_contacts_parse_and_generate(self): |
|
74 fs = filestorage.FileStorage(testdata) |
|
75 p = api.Project(fs) |
|
76 config = p.get_configuration('product.confml') |
|
77 impls = plugin.get_impl_set(config,'\.gcfml$') |
|
78 impls.output = self.output |
|
79 impl = impls.get_implementations_by_file('assets/s60/implml/predefinedcontacts.gcfml')[0] |
|
80 impls.generate() |
|
81 |
|
82 def test_write_element_fo_file(self): |
|
83 ''' |
|
84 Fix this |
|
85 ''' |
|
86 OUTFILE = os.path.join(ROOT_PATH, 'temp/elementfile.xml') |
|
87 if not os.path.exists(os.path.join(ROOT_PATH, 'temp')): |
|
88 os.makedirs(os.path.join(ROOT_PATH, 'temp')) |
|
89 #fs = filestorage.FileStorage(testdata) |
|
90 #p = api.Project(fs) |
|
91 #config = p.get_configuration('product.confml') |
|
92 #genconfml_plugin = genconfmlplugin.GenconfmlImpl(None, config) |
|
93 element = ElementTree.fromstring('<test>kfkadl</test>') |
|
94 |
|
95 genconfmlplugin.write_element(element, OUTFILE) |
|
96 self.assertTrue(os.path.exists(OUTFILE)) |
|
97 #out_file = open(output, 'r') |
|
98 #out_file.write(xml.etree.ElementTree.tostring(element)) |
|
99 #out_file.close() |
|
100 |
|
101 |
|
102 #resource = self.configuration.get_resource("elementfile.xml") |
|
103 |
|
104 |
|
105 def test_parse_target(self): |
|
106 etree = ElementTree.fromstring(genconfgml_string) |
|
107 reader = genconfmlplugin.GenconfmlImplReader() |
|
108 target = reader.parse_target(etree) |
|
109 self.assertEquals(target,'output') |
|
110 |
|
111 def test_parse_stylesheet(self): |
|
112 etree = ElementTree.fromstring(genconfgml_string) |
|
113 reader = genconfmlplugin.GenconfmlImplReader() |
|
114 stylesheet = reader.parse_stylesheet(etree) |
|
115 #print stylesheet |
|
116 #FIX THIS |
|
117 #self.assertEquals(stylesheet, etree.find("{%s}stylesheet" % 'http://www.w3.org/1999/XSL/Transform')) |
|
118 |
|
119 def test_parse_name(self): |
|
120 etree = ElementTree.fromstring(genconfgml_string) |
|
121 reader = genconfmlplugin.GenconfmlImplReader() |
|
122 name = reader.parse_name(etree) |
|
123 self.assertEquals(name,'Setting/Data.xml') |
|
124 |
|
125 def test_parse_subdir_without_definition(self): |
|
126 etree = ElementTree.fromstring(genconfgml_string) |
|
127 reader = genconfmlplugin.GenconfmlImplReader() |
|
128 subdir = reader.parse_subdir(etree) |
|
129 self.assertEquals(subdir, "") |
|
130 |
|
131 def test_parse_subdir_with_definition(self): |
|
132 etree = ElementTree.fromstring(genconfgml_string.replace("target=\"output\"", "subdir=\"include\"")) |
|
133 reader = genconfmlplugin.GenconfmlImplReader() |
|
134 subdir = reader.parse_subdir(etree) |
|
135 self.assertEquals(subdir, "include") |
|
136 |
|
137 def test_parse_settings(self): |
|
138 etree = ElementTree.fromstring(genconfgml_string) |
|
139 reader = genconfmlplugin.GenconfmlImplReader() |
|
140 settings = reader.parse_settings(etree) |
|
141 self.assertEquals(settings[0],'Setting/Settings') |
|
142 self.assertEquals(settings[1],'Setting/ContentSettings') |
|
143 |
|
144 def test_has_ref(self): |
|
145 fs = filestorage.FileStorage(testdata) |
|
146 p = api.Project(fs) |
|
147 config = p.get_configuration('product.confml') |
|
148 impls = plugin.get_impl_set(config,'\.gcfml$') |
|
149 impls.output = self.output |
|
150 impl = impls.get_implementations_by_file('assets/s60/implml/predefinedcontacts.gcfml')[0] |
|
151 self.assertEquals(impl.get_refs(), ['Contacts.Contact']) |
|
152 self.assertFalse(impl.has_ref(['ref1', 'ref2'])) |
|
153 self.assertTrue(impl.has_ref(['Contacts.Contact'])) |
|
154 self.assertTrue(impl.has_ref(['Contacts.Contact.FirstName'])) |
|
155 self.assertFalse(impl.has_ref(['Contacts.OtherSetting'])) |
|
156 |
|
157 def test_list_output_files(self): |
|
158 fs = filestorage.FileStorage(testdata) |
|
159 p = api.Project(fs) |
|
160 config = p.get_configuration('product.confml') |
|
161 impls = plugin.get_impl_set(config,'\.gcfml$') |
|
162 impls.output = self.output |
|
163 impl = impls.get_implementations_by_file('assets/s60/implml/predefinedcontacts.gcfml')[0] |
|
164 self.assertEquals(impl.list_output_files(), ['output\\private\\2000BEE5\\predefinedcontacts.xml']) |
|
165 |
|
166 |
|
167 if __name__ == '__main__': |
|
168 unittest.main() |