#!/bin/sh

# Test of GtkBuilder support.
# Checks that the extracted pot contains the right translatable
# content, comments and context.

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

tmpfiles="$tmpfiles xg-gl-6-empty.glade"
cat <<EOF > xg-gl-6-empty.glade
<?xml version="1.0"?>
<GTK-Interface/>
EOF

tmpfiles="$tmpfiles xg-gl-6.pot"
: ${XGETTEXT=xgettext}
${XGETTEXT} -o xg-gl-6.pot xg-gl-6-empty.glade 2>/dev/null
test $? = 0 || {
  echo "Skipping test: xgettext was built without Glade support"
  rm -fr $tmpfiles; exit 77
}

tmpfiles="$tmpfiles xg-gl-6.ui"
cat <<EOF > xg-gl-6.ui
<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <!-- interface-requires gtk+ 3.0 -->
  <object class="GtkWindow" id="window">
    <property name="can_focus">False</property>
    <property name="title" translatable="yes" context="This is the context for this text" comments="This is a comment for empty window">This is an empty window</property>
    <child>
      <placeholder/>
    </child>
  </object>
</interface>
EOF

tmpfiles="$tmpfiles xg-gl-6.pot"
: ${XGETTEXT=xgettext}
${XGETTEXT} -o - xg-gl-6.ui | grep -v 'POT-Creation-Date' > xg-gl-6.pot
test $? = 0 || { rm -fr $tmpfiles; exit 1; }

tmpfiles="$tmpfiles xg-gl-6.ok"
cat <<EOF > xg-gl-6.ok
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#. This is a comment for empty window
#: xg-gl-6.ui:6
msgctxt "This is the context for this text"
msgid "This is an empty window"
msgstr ""
EOF

: ${DIFF=diff}
${DIFF} xg-gl-6.ok xg-gl-6.pot
result=$?

rm -fr $tmpfiles

exit $result
