コード例 #1
0
ファイル: ModuleTest.cs プロジェクト: bdqnghi/j2cstranslator
 protected internal ModuleTest(String baseName_0, String locName)
 {
     this.t          = null;
     this.localeName = null;
     this.baseName   = null;
     localeName      = locName;
     this.baseName   = baseName_0;
 }
コード例 #2
0
ファイル: ModuleTest.cs プロジェクト: bdqnghi/j2cstranslator
 /// <summary>
 /// Open the test data in the module with the given name, and return true if
 /// success. The current test is reset.
 /// </summary>
 ///
 /// <exception cref="TestDataModule_Constants.DataModuleFormatError"></exception>
 protected internal bool OpenTestData(String name)
 {
     try {
         t = (m == null) ? null : m.GetTestData(name);
     } catch (TestDataModule_Constants.DataModuleFormatError e) {
         return(false);
     }
     return(t != null);
 }
コード例 #3
0
        private void TestConvert(TestDataModule_Constants.TestData testData,
                                 IBM.ICU.Charset.TestDataModule_Constants.DataMap settings, bool forward)
        {
            Calendar toCalendar = null;
            // build to calendar
            String  testSetting = settings.GetString("ToCalendar");
            ULocale loc         = new ULocale(testSetting);

            toCalendar = IBM.ICU.Util.Calendar.GetInstance(loc);
            CalendarFieldsSet fromSet = new CalendarFieldsSet(), toSet = new CalendarFieldsSet();
            // DateFormat fmt = new
            // SimpleDateFormat("EEE MMM dd yyyy / YYYY'-W'ww-ee");
            // Start the processing
            int n = 0;

            for (IIterator iter = testData.GetDataIterator(); iter.HasNext();)
            {
                ++n;
                IBM.ICU.Charset.TestDataModule_Constants.DataMap currentCase = (IBM.ICU.Charset.TestDataModule_Constants.DataMap)iter.Next();

                String   caseString   = "[" + testData.GetName() + "#" + n + " " + "]";
                String   locale       = testSetting = currentCase.GetString("locale");
                ULocale  fromLoc      = new ULocale(testSetting);
                Calendar fromCalendar = IBM.ICU.Util.Calendar.GetInstance(fromLoc);

                fromSet.Clear();
                toSet.Clear();

                String from = currentCase.GetString("from");
                fromSet.ParseFrom(from);
                String to = currentCase.GetString("to");
                toSet.ParseFrom(to, fromSet);

                // now, do it.
                if (forward)
                {
                    Logln(caseString + " " + locale + "/" + from + " >>> " + loc
                          + "/" + to);
                    TestConvert(caseString, fromSet, fromCalendar, toSet,
                                toCalendar, forward);
                }
                else
                {
                    Logln(caseString + " " + locale + "/" + from + " <<< " + loc
                          + "/" + to);
                    TestConvert(caseString, toSet, toCalendar, fromSet,
                                fromCalendar, forward);
                }
            }
        }
コード例 #4
0
        private void TestOps(TestDataModule_Constants.TestData testData, IBM.ICU.Charset.TestDataModule_Constants.DataMap settings)
        {
            // Get 'from' time
            CalendarFieldsSet fromSet = new CalendarFieldsSet(), toSet = new CalendarFieldsSet(), paramsSet = new CalendarFieldsSet(), diffSet = new CalendarFieldsSet();
            // DateFormat fmt = new
            // SimpleDateFormat("EEE MMM dd yyyy / YYYY'-W'ww-ee");
            // Start the processing
            int n = 0;

            for (IIterator iter = testData.GetDataIterator(); iter.HasNext();)
            {
                ++n;
                IBM.ICU.Charset.TestDataModule_Constants.DataMap currentCase = (IBM.ICU.Charset.TestDataModule_Constants.DataMap)iter.Next();

                String caseString = "[case " + n + "]";
                // build to calendar
                // Headers { "locale","from","operation","params","to" }
                // #1 locale
                String param = "locale";
                String locale;
                String testSetting = currentCase.GetString(param);
                locale = testSetting;
                ULocale  loc          = new ULocale(locale);
                Calendar fromCalendar = IBM.ICU.Util.Calendar.GetInstance(loc);

                fromSet.Clear();
                // #2 'from' info
                param = "from";
                String from = testSetting = currentCase.GetString(param);
                fromSet.ParseFrom(testSetting);
                // System.err.println("fromset: ["+testSetting+"] >> " + fromSet);

                // #4 'operation' info
                param = "operation";
                String operation = testSetting = currentCase.GetString(param);
                paramsSet.Clear();
                // #3 'params' info
                param = "params";
                String paramsData = testSetting = currentCase.GetString(param);
                paramsSet.ParseFrom(paramsData); // parse with inheritance.
                // System.err.println("paramsSet: ["+testSetting+"] >> " +
                // paramsSet);

                toSet.Clear();
                // #4 'to' info
                param = "to";
                String to = testSetting = currentCase.GetString(param);
                toSet.ParseFrom(testSetting, fromSet); // parse with inheritance.
                // System.err.println("toSet: ["+testSetting+"] >> " + toSet);

                String caseContentsString = locale + ":  from " + from + ": "
                                            + operation + " [[[ " + paramsSet + " ]]]   >>> " + to;
                Logln(caseString + ": " + caseContentsString);

                // ------
                // now, do it.

                // / prepare calendar
                fromSet.SetOnCalendar(fromCalendar);

                // from calendar: 'starting date'

                diffSet.Clear();

                // Is the calendar sane after being set?
                if (!fromSet.Matches(fromCalendar, diffSet))
                {
                    String diffs = diffSet.DiffFrom(fromSet);
                    Errln((String)"FAIL: " + caseString
                          + ", SET SOURCE calendar was not set: Differences: "
                          + diffs);
                }
                else
                {
                    Logln(" " + caseString + " SET SOURCE calendar match."); // verifies
                    // that
                    // the
                    // requested
                    // fields
                    // were
                    // set.
                }

                // to calendar - copy of from calendar
                Calendar toCalendar = (Calendar)fromCalendar.Clone();

                // / perform op on 'to calendar'
                for (int q = 0; q < paramsSet.FieldCount(); q++)
                {
                    if (paramsSet.IsSet(q))
                    {
                        if (operation.Equals(kROLL))
                        {
                            toCalendar.Roll(q, paramsSet.Get(q));
                        }
                        else if (operation.Equals(kADD))
                        {
                            toCalendar.Add(q, paramsSet.Get(q));
                        }
                        else
                        {
                            Errln(caseString + " FAIL: unknown operation "
                                  + operation);
                        }
                        Logln(operation + " of " + paramsSet.Get(q));
                    }
                }
                // now - what's the result?
                diffSet.Clear();

                // toset contains 'expected'

                if (!toSet.Matches(toCalendar, diffSet))
                {
                    String diffs_0 = diffSet.DiffFrom(toSet);
                    Errln((String)"FAIL: " + caseString + " - , "
                          + caseContentsString + " Differences: " + diffs_0);
                }
                else
                {
                    Logln("PASS: "******" matched! ");
                }
            }
        }