#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Libreoffice macro to reproduce Debian bug 718403
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=718403

"""


def bug(arg1):
  """
  Minimal script to trigger the error
  """

  # get active document
  document = XSCRIPTCONTEXT.getDocument()

  # use sheet BUG
  feuille = document.Sheets.getByName("BUG")

  # check unicode
  try:
    feuille.getCellByPosition (0, 1).setString("Meuh")
  except:
    feuille.getCellByPosition (0, 1).setString("not OK")

  try:
    feuille.getCellByPosition (0, 2).setString("Meuh")
  except:
    feuille.getCellByPosition (0, 2).setString("not OK")

  try:
    feuille.getCellByPosition (0, 3).setString("éèà")
  except:
    feuille.getCellByPosition (0, 3).setString("not OK")

  try:
    feuille.getCellByPosition (0, 4).setString("éèà".encode('iso-8859-1'))
  except:
    feuille.getCellByPosition (0, 4).setString("not OK")

  try:
    feuille.getCellByPosition (0, 5).setString("%s" % (type("éèà")))
  except:
    feuille.getCellByPosition (0, 5).setString('erreur type')

