From 4f3d274fb8a7f83362a9eacbf1063e346be5f535 Mon Sep 17 00:00:00 2001
From: Sebastien Robin <seb@nexedi.com>
Date: Wed, 26 May 2004 08:41:46 +0000
Subject: [PATCH] corrected bug when we cut big message with string wich
 contains -- character

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@922 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5SyncML/Subscription.py         |  2 +
 product/ERP5SyncML/SyncCode.py             |  2 +-
 product/ERP5SyncML/XMLSyncUtils.py         |  7 +++
 product/ERP5SyncML/tests/testERP5SyncML.py | 69 ++++++++++++++++++----
 4 files changed, 66 insertions(+), 14 deletions(-)

diff --git a/product/ERP5SyncML/Subscription.py b/product/ERP5SyncML/Subscription.py
index 21219fb509..264cbe7f3c 100755
--- a/product/ERP5SyncML/Subscription.py
+++ b/product/ERP5SyncML/Subscription.py
@@ -409,6 +409,8 @@ class Signature(SyncCode):
     deliver in the future
     """
     #LOG('Subscriber.getPartialXML',0,'partial_xml: %s' % str(self.partial_xml))
+    if self.partial_xml is not None:
+      self.partial_xml = self.partial_xml.replace('@-@@-@','--') # need to put back '--'
     return self.partial_xml
 
   def getAction(self):
diff --git a/product/ERP5SyncML/SyncCode.py b/product/ERP5SyncML/SyncCode.py
index 47894f5359..749d5e42e8 100755
--- a/product/ERP5SyncML/SyncCode.py
+++ b/product/ERP5SyncML/SyncCode.py
@@ -63,7 +63,7 @@ class SyncCode(Persistent):
   PUB_CONFLICT_MERGE = 6
   PUB_CONFLICT_CLIENT_WIN = 8
 
-  MAX_LINES = 10000
+  MAX_LINES = 1000
 
   action_tag = 'workflow_action'
   #NOT_EDITABLE_PROPERTY = ('id','object','uid','xupdate:element',action_tag,
diff --git a/product/ERP5SyncML/XMLSyncUtils.py b/product/ERP5SyncML/XMLSyncUtils.py
index cb782dd465..944bd7c3a3 100755
--- a/product/ERP5SyncML/XMLSyncUtils.py
+++ b/product/ERP5SyncML/XMLSyncUtils.py
@@ -572,6 +572,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
           signature = Signature(gid=object_gid,id=object.getId())
           signature.setTempXML(xml_object)
           if xml_string.count('\n') > self.MAX_LINES:
+            if xml_string.find('--') > 0: # This make comment fails, so we need to replace
+              xml_string = xml_string.replace('--','@-@@-@')
             more_data=1
             i = 0
             short_string = ''
@@ -606,6 +608,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
                                               xml_mapping=domain.xml_mapping,
                                               old_xml=signature.getXML())
             if xml_string.count('\n') > self.MAX_LINES:
+              if xml_string.find('--') > 0: # This make comment fails, so we need to replace
+                xml_string = xml_string.replace('--','@-@@-@')
               i = 0
               more_data=1
               short_string = ''
@@ -642,6 +646,7 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
           # XXX previous_xml will be getXML instead of getTempXML because
           # some modification was already made and the update
           # may not apply correctly
+          xml_update = signature.getPartialXML()
           conduit.updateNode(xml=signature.getPartialXML(), object=object,
                             previous_xml=signature.getXML(),force=1)
           xml_confirmation += self.SyncMLConfirmation(cmd_id,object_gid,
@@ -650,6 +655,8 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
         elif signature.getStatus()==self.PARTIAL:
           xml_string = signature.getPartialXML()
           if xml_string.count('\n') > self.MAX_LINES:
+            if xml_string.find('--') > 0: # This make comment fails, so we need to replace
+              xml_string = xml_string.replace('--','@-@@-@')
             i = 0
             more_data=1
             short_string = ''
diff --git a/product/ERP5SyncML/tests/testERP5SyncML.py b/product/ERP5SyncML/tests/testERP5SyncML.py
index c7bf1f7dda..40b636b8f4 100755
--- a/product/ERP5SyncML/tests/testERP5SyncML.py
+++ b/product/ERP5SyncML/tests/testERP5SyncML.py
@@ -57,14 +57,14 @@ class TestERP5SyncML(ERP5TypeTestCase):
   workflow_id = 'edit_workflow'
   first_name1 = 'Sebastien'
   last_name1 = 'Robin'
-  description1 = 'description1 $sdfrç_sdfsçdf_oisfsopf'
+  description1 = 'description1 --- $sdfrç_sdfsçdf_oisfsopf'
   lang1 = 'fr'
   format2 = 'html'
   format3 = 'xml'
   format4 = 'txt'
   first_name2 = 'Jean-Paul'
   last_name2 = 'Smets'
-  description2 = 'description2éà@  $*< <<<  >>>></title>&oekd'
+  description2 = 'description2éà@  $*< <<<  ----- >>>></title>&oekd'
   lang2 = 'en'
   first_name3 = 'Yoshinori'
   last_name3 = 'Okuji'
@@ -94,7 +94,7 @@ class TestERP5SyncML(ERP5TypeTestCase):
       Return the list of business templates.
 
       the business template sync_crm give 3 folders:
-      /person_server with persons: 170,171, 180
+      /person_server 
       /person_client1 : empty
       /person_client2 : empty
     """
@@ -122,9 +122,9 @@ class TestERP5SyncML(ERP5TypeTestCase):
       ZopeTestCase._print('\nTest Has Everything ')
       LOG('Testing... ',0,'testHasEverything')
     self.failUnless(self.getSynchronizationTool()!=None)
-    self.failUnless(self.getPersonServer()!=None)
-    self.failUnless(self.getPersonClient1()!=None)
-    self.failUnless(self.getPersonClient2()!=None)
+    #self.failUnless(self.getPersonServer()!=None)
+    #self.failUnless(self.getPersonClient1()!=None)
+    #self.failUnless(self.getPersonClient2()!=None)
 
   def testAddPublication(self, quiet=0, run=run_all_test):
     if not run: return
@@ -177,8 +177,21 @@ class TestERP5SyncML(ERP5TypeTestCase):
       ZopeTestCase._print('\nTest Populate Person Server ')
       LOG('Testing... ',0,'populatePersonServer')
     self.login()
-    person_server = self.getPersonServer()
+    portal = self.getPortal()
+    if not hasattr(portal,'person_server'):
+      portal.portal_types.constructContent(type_name = 'Person Module',
+                                           container = portal,
+                                           id = 'person_server')
+    if not hasattr(portal,'person_client1'):
+      portal.portal_types.constructContent(type_name = 'Person Module',
+                                           container = portal,
+                                           id = 'person_client1')
+    if not hasattr(portal,'person_client2'):
+      portal.portal_types.constructContent(type_name = 'Person Module',
+                                           container = portal,
+                                           id = 'person_client2')
     person_id = ''
+    person_server = self.getPersonServer()
     person1 = person_server.newContent(id=self.id1,portal_type='Person')
     kw = {'first_name':self.first_name1,'last_name':self.last_name1,
           'description':self.description1}
@@ -350,6 +363,36 @@ class TestERP5SyncML(ERP5TypeTestCase):
     self.failUnless(person2_c.getFirstName()==self.first_name1)
     self.failUnless(person2_c.getLastName()==self.last_name1)
 
+  def testFirstSynchronizationWithLongLines(self, quiet=0, run=run_all_test):
+    # We will try to populate the folder person_client1
+    # with the data form person_server
+    if not run: return
+    if not quiet:
+      ZopeTestCase._print('\nTest First Synchronization With Long Lines ')
+      LOG('Testing... ',0,'testFirstSynchronizationWithLongLines')
+    self.login()
+    self.setupPublicationAndSubscription(quiet=1,run=1)
+    nb_person = self.populatePersonServer(quiet=1,run=1)
+    person_server = self.getPersonServer()
+    long_line = 'a' * 10000 + ' --- '
+    person1_s = person_server._getOb(self.id1)
+    kw = {'first_name':long_line} 
+    person1_s.edit(**kw)
+    # Synchronize the first client
+    nb_message1 = self.synchronize(self.sub_id1)
+    self.failUnless(nb_message1==self.nb_message_first_synchronization)
+    portal_sync = self.getSynchronizationTool()
+    subscription1 = portal_sync.getSubscription(self.sub_id1)
+    self.failUnless(len(subscription1.getObjectList())==nb_person)
+    self.failUnless(person1_s.getId()==self.id1)
+    self.failUnless(person1_s.getFirstName()==long_line)
+    self.failUnless(person1_s.getLastName()==self.last_name1)
+    person_client1 = self.getPersonClient1()
+    person1_c = person_client1._getOb(self.id1)
+    self.failUnless(person1_c.getId()==self.id1)
+    self.failUnless(person1_c.getFirstName()==long_line)
+    self.failUnless(person1_c.getLastName()==self.last_name1)
+
   def testGetObjectFromGid(self, quiet=0, run=run_all_test):
     # We will try to get an object from a publication
     # just by givin the gid
@@ -1029,12 +1072,12 @@ class TestERP5SyncML(ERP5TypeTestCase):
     self.failUnless(len_path==3)
     len_path = len(sub_sub_person2.getPhysicalPath()) - 3 
     self.failUnless(len_path==3)
-    self.failUnless(sub_sub_person1.getDescription()==self.description1)
-    self.failUnless(sub_sub_person1.getFirstName()==self.first_name1)
-    self.failUnless(sub_sub_person1.getLastName()==self.last_name1)
-    self.failUnless(sub_sub_person2.getDescription()==self.description2)
-    self.failUnless(sub_sub_person2.getFirstName()==self.first_name2)
-    self.failUnless(sub_sub_person2.getLastName()==self.last_name2)
+    self.assertEquals(sub_sub_person1.getDescription(),self.description1)
+    self.assertEquals(sub_sub_person1.getFirstName(),self.first_name1)
+    self.assertEquals(sub_sub_person1.getLastName(),self.last_name1)
+    self.assertEquals(sub_sub_person2.getDescription(),self.description2)
+    self.assertEquals(sub_sub_person2.getFirstName(),self.first_name2)
+    self.assertEquals(sub_sub_person2.getLastName(),self.last_name2)
     SyncCode.MAX_LINES = previous_max_lines
 
   # We may add a test in order to check if the slow_sync mode works fine, ie
-- 
2.30.9