#!/usr/bin/env ruby
# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH.unshift("../lib")
$LOAD_PATH.unshift("../compat")
require "test/unit"
require "statlog"
require "qwik/qp"

class TC_LogLine < Test::Unit::TestCase
  def test_logline
    line = '2004-10-20T08:40:32 usr1.e.jp test@e.com "GET /test/1.html" 200 28083'
    logline = LogLine.new(line)
    #assert_equal("Wed Oct 20 08:40:32 GMT+9:00 2004", logline.date.to_s)
    assert_equal("Wed Oct 20 00:00:00 GMT+9:00 2004", logline.date.to_s)
    assert_equal("usr1.e.jp", logline.host)
    assert_equal("test@e.com", logline.user)
    assert_equal("GET", logline.method)
    assert_equal("/test/1.html", logline.path)
    assert_equal("200", logline.status)
    assert_equal("28083", logline.byte)

    date, timestr = logline.parse_date("2004-10-20T08:40:32")
    assert_equal("Wed Oct 20 00:00:00 GMT+9:00 2004", date.to_s)
    assert_equal("04102008", timestr)
  end

  def test_with_comma
    line = '2004-09-02T09:00:49 unknown, 220.2.3.4 t@k.jp "GET /test/23.html" 200 7602'
    logline = LogLine.new(line)
    assert_equal("unknown,220.2.3.4", logline.host)
  end
end
