logrecordserializer_test.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. goog.provide('goog.debug.logRecordSerializerTest');
  15. goog.setTestOnly('goog.debug.logRecordSerializerTest');
  16. goog.require('goog.debug.LogRecord');
  17. goog.require('goog.debug.Logger');
  18. goog.require('goog.debug.logRecordSerializer');
  19. goog.require('goog.testing.jsunit');
  20. var NOW = 1311484654000;
  21. var SEQ = 1231;
  22. function testBasic() {
  23. var rec = new goog.debug.LogRecord(
  24. goog.debug.Logger.Level.FINE, 'An awesome message', 'logger.name', NOW,
  25. SEQ);
  26. var thawed = goog.debug.logRecordSerializer.parse(
  27. goog.debug.logRecordSerializer.serialize(rec));
  28. assertEquals(goog.debug.Logger.Level.FINE, thawed.getLevel());
  29. assertEquals('An awesome message', thawed.getMessage());
  30. assertEquals('logger.name', thawed.getLoggerName());
  31. assertEquals(NOW, thawed.getMillis());
  32. assertEquals(SEQ, thawed.getSequenceNumber());
  33. assertNull(thawed.getException());
  34. }
  35. function testWithException() {
  36. var err = new Error('it broke!');
  37. var rec = new goog.debug.LogRecord(
  38. goog.debug.Logger.Level.FINE, 'An awesome message', 'logger.name', NOW,
  39. SEQ);
  40. rec.setException(err);
  41. var thawed = goog.debug.logRecordSerializer.parse(
  42. goog.debug.logRecordSerializer.serialize(rec));
  43. assertEquals(err.message, thawed.getException().message);
  44. }
  45. function testCustomLogLevel() {
  46. var rec = new goog.debug.LogRecord(
  47. new goog.debug.Logger.Level('CUSTOM', -1), 'An awesome message',
  48. 'logger.name', NOW, SEQ);
  49. var thawed = goog.debug.logRecordSerializer.parse(
  50. goog.debug.logRecordSerializer.serialize(rec));
  51. assertEquals('CUSTOM', thawed.getLevel().name);
  52. assertEquals(-1, thawed.getLevel().value);
  53. }
  54. function testWeirdLogLevel() {
  55. var rec = new goog.debug.LogRecord(
  56. new goog.debug.Logger.Level('FINE', -1), 'An awesome message',
  57. 'logger.name', NOW, SEQ);
  58. var thawed = goog.debug.logRecordSerializer.parse(
  59. goog.debug.logRecordSerializer.serialize(rec));
  60. assertEquals('FINE', thawed.getLevel().name);
  61. // Makes sure that the log leve is still -1 even though the name
  62. // FINE is predefind.
  63. assertEquals(-1, thawed.getLevel().value);
  64. }